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 日

1 投票

fid=fopen('11_20114111611_logfile.txt','r')
k=textscan(fid,'%d%d%d%d')
cell2mat (k)

14 件のコメント

suganya s
suganya s 2015 年 8 月 20 日
ya i use this also but it will show error as invalid file identifier? how can i proceed?
Purushottama Rao
Purushottama Rao 2015 年 8 月 21 日
編集済み: Purushottama Rao 2015 年 8 月 21 日
In my opinion, ypu should not get 'invalid file identifier' with fopen command. fopen returns -1 if file open is failed. Can you give the screen shot after typing the first command?
Purushottama Rao
Purushottama Rao 2015 年 8 月 21 日
Its working for me...
>> fid=fopen('11_20114111611_logfile.txt','r')
fid =
5
suganya s
suganya s 2015 年 8 月 21 日
yes sir,fid return -1,then how can i proceed
suganya s
suganya s 2015 年 8 月 21 日
here the screen shot then tell me what is the problem how can read a file
suganya s
suganya s 2015 年 8 月 21 日
i get this ans now..how can i read filder
Purushottama Rao
Purushottama Rao 2015 年 8 月 21 日
Is the current folder consists the file '11_20114111611_logfile.txt'??
suganya s
suganya s 2015 年 8 月 21 日
yes the folder consists of the above file 20 more file
Purushottama Rao
Purushottama Rao 2015 年 8 月 21 日
Iam confuesd a bit. Could you able to read the data in one file into a matrix??
suganya s
suganya s 2015 年 8 月 24 日
yes i read one file...........any for loop we use?
suganya s
suganya s 2015 年 8 月 24 日
any for loop want to use to read a folder?
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 日

0 投票

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 日

0 投票

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 日

0 投票

how can i read a entire folder within 2 3 steps?????

カテゴリ

ヘルプ センター および File Exchange で Large Files and Big Data についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by