Read Data From txt file using uigetfile...

Hi
I Have to read a file using uigetfile by this code by i face the error...
[filename,pathname,d] = uigetfile('*.txt;');
filepath=fullfile('pathname','filename');
fid = fopen('filepath');
mline1 = textscan(fid, '%f%s%s%f%f%s%s%f%f ','HeaderLines',5);
fclose(fid);
Error:
Error using textscan
Invalid file identifier. Use fopen to generate a valid
file identifier.
By The Way I Already have done it without using uigetfile...
another point is data should be a number not a string cause they are going to plotted... What should i do to convert them???

1 件のコメント

Walter Roberson
Walter Roberson 2013 年 6 月 21 日
For the bit about it needing to be a number, we need a sample input line.

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

 採用された回答

Walter Roberson
Walter Roberson 2013 年 6 月 21 日

1 投票

do not put the aote matks around filepath.
fopen(filepath)

9 件のコメント

Masoud Ghanbari
Masoud Ghanbari 2013 年 6 月 21 日
I Need To Use uigetfile... Actually
Walter Roberson
Walter Roberson 2013 年 6 月 21 日
[filename,pathname,d] = uigetfile('*.txt;');
filepath=fullfile('pathname','filename');
fid = fopen(filepath); %no quotes around filepath
Masoud Ghanbari
Masoud Ghanbari 2013 年 6 月 22 日
Dear Walter...
the error is for this line :
mline1 = textscan(fid, '%f%s%s%f%f%s%s%f%f ','HeaderLines',5);
and the error's text is again the above one...
Walter Roberson
Walter Roberson 2013 年 6 月 22 日
[filename,pathname,d] = uigetfile('*.txt;');
filepath=fullfile(pathname, filename); %no quotes around pathname, filename
fid = fopen(filepath); %no quotes around filepath
Masoud Ghanbari
Masoud Ghanbari 2013 年 6 月 22 日
thanks but the results is shown like:
[10x1 double]
i want them to be a real number cause they have to be added and plotted...
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 22 日
cell2mat(YourArray)
Masoud Ghanbari
Masoud Ghanbari 2013 年 6 月 22 日
編集済み: Masoud Ghanbari 2013 年 6 月 22 日
cell2mat does not work when i have %f or %s in the textscan command... such a like this...
mline1_cell= textscan(fid, '%d %d %f %f %f %s %d %*[^\n] ','HeaderLines',5);
cell2mat(mline1)
>> error
????
Walter Roberson
Walter Roberson 2013 年 6 月 22 日
mline_num = [mline1{[1:5 7]}];
mline_txt = mline1{6};
Masoud Ghanbari
Masoud Ghanbari 2013 年 6 月 23 日
Thanks Dear Walter And Dear Azzi...

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by