data.dat
次の内容の名前のファイルがあります。
私の名前はエリアス 123
これは本です 123.450
父の名前 -2.34e+05
このファイルを MATLAB に読み込み、次のデータを出力として取得します。
a = 123
b = 123.450
c = -2.34e+05
name = 'elyas'
しかし、これを行う方法がわかりません。助言がありますか?
data.dat
次の内容の名前のファイルがあります。
私の名前はエリアス 123
これは本です 123.450
父の名前 -2.34e+05
このファイルを MATLAB に読み込み、次のデータを出力として取得します。
a = 123
b = 123.450
c = -2.34e+05
name = 'elyas'
しかし、これを行う方法がわかりません。助言がありますか?
TEXTSCANを使用して 3 行のそれぞれを読み取る1 つの方法を次に示します。
fid = fopen('data.dat','rt'); %# Open the file
data = textscan(fid,'%*s %*s %*s %s %f',1); %# Read the first line, ignoring
%# the first 3 strings
name = data{1}{1}; %# Get the string 'name'
a = data{2}; %# Get the value for 'a'
data = textscan(fid,'%*s %*s %*s %*s %f',1); %# Read the second line, ignoring
%# the first 4 strings
b = data{1}; %# Get the value for 'b'
data = textscan(fid,'%*s %*s %*s %f',1); %# Read the third line, ignoring
%# the first 3 strings
c = data{1}; %# Get the value for 'c'
fclose(fid); %# Close the file
textscanを試すことができます。