필터 지우기
필터 지우기

how to read a file in matrix format?

조회 수: 1 (최근 30일)
suganya s
suganya s 2015년 8월 19일
편집: Walter Roberson 2015년 8월 24일
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????????

채택된 답변

Purushottama Rao
Purushottama Rao 2015년 8월 19일
fid=fopen('11_20114111611_logfile.txt','r')
k=textscan(fid,'%d%d%d%d')
cell2mat (k)
  댓글 수: 14
suganya s
suganya s 2015년 8월 24일
if we use dir command in matlab then can i read the folder?????
Walter Roberson
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개)

suganya s
suganya s 2015년 8월 19일
how to read file in matrix format?????
am having the following file i want read the file in matrix format. i used fscanf command but the file content was changed.......

Walter Roberson
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

suganya s
suganya s 2015년 8월 21일
how can i read a entire folder within 2 3 steps?????

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by