how to read a file in matrix format?
3 次查看(过去 30 天)
显示 更早的评论
am having a following file and i used "fscanf" to read the file in matrix format,but it will display the value after some calculation... the content could be changed?
also how to read a multiple file with in a folder in matrix format????????
0 个评论
采纳的回答
Purushottama Rao
2015-8-19
fid=fopen('11_20114111611_logfile.txt','r')
k=textscan(fid,'%d%d%d%d')
cell2mat (k)
14 个评论
Walter Roberson
2015-8-24
编辑:Walter Roberson
2015-8-24
dinfo = dir('*.txt');
for K = 1 : length(dinfo)
thisfile = dinfo(K).name;
fid = fopen(thisfile, 'rt');
datacell = textscan(fid, '%d%d%d%d', 'CollectOutput', 1);
fclose(fid);
logdata(K).filename = thisfile;
logdata(K).data = datacell{1};
end
Now logdata will be a structure with one entry for every file, with fields "filename" and "data".
You cannot do it in "2 3 steps". You need at least 4 steps: getting the file names, looping over the names, opening each file, reading the data from the file.
更多回答(3 个)
Walter Roberson
2015-8-20
Your data was not changed. You need to use the command
format long g
to see the data in the form you would like. Currently you are using
format short
which requests a compact view that reduces the number of displayed decimal places in order to reduce the amount of output.
To read multiple files see
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!