How to read a special column from a file?

2 ビュー (過去 30 日間)
ali mohebi
ali mohebi 2018 年 10 月 22 日
コメント済み: ali mohebi 2018 年 10 月 23 日
Hy I have this file 'FAR.RSM' produced by another software, now i want MATLAB to read the numbers under column of 'FOE' (you see it in the file) to be used as an input for other calculations, i use this code but it gives me this error: 'Unrecognized variable name 'FOE''. i forgot to say that its columns' may change in order and number. the loaded file here is in 'txt' format and the one i have is in 'RSM' format, it couldn't be loaded here so i changed it in 'txt' format.
opt = detectImportOptions('FAR.RSM','FileType','text'); T = readtable('FAR.RSM', opt); GOE = T.FOE(end)
Great thanks.
  2 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 22 日
What’s the file format and upload the file
ali mohebi
ali mohebi 2018 年 10 月 22 日
'.RSM' is the format i'm using, but here it is in '.txt' format.

サインインしてコメントする。

回答 (1 件)

madhan ravi
madhan ravi 2018 年 10 月 22 日
編集済み: madhan ravi 2018 年 10 月 22 日
fid = fopen('FAR.txt')
f= textscan(fid,'%s ' , 'delimiter','\n')
fclose(fid)
c=f{1,1}(10:16)
c=str2num(cell2mat(c))
c=c(:,3) %reads third column
  4 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 22 日
because the text file you uploaded is scattered
ali mohebi
ali mohebi 2018 年 10 月 23 日
this is the code i use for both of these files, first i convert '.RSM' to '.txt' then with 'readtable' the contents is read in columns, but it works for the 'txt.1' file and not for '.txt.2', what should i do to work for the second one, because those are the same files with different numbers!
fid=fopen('FAR.txt','w'); copyfile FAR.RSM FAR.txt fclose(fid); opt = detectImportOptions('FAR.txt','FileType','text'); T = readtable('FAR.txt',opt); GOE(i) = T.FOE(end)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by