how to use fopen in this situation?

1 回表示 (過去 30 日間)
Meisam
Meisam 2012 年 3 月 9 日
Hi I have created a Function like the following function, the function acceopts a Text file name as input. I want to open this text file with fopen, but it seems it is not possible. what can I do? here is the function:
function myfunction =rob2xml
prompt={'Textfilename.txt(Ex:test1.txt)'};
dlg_title='Joint values;
num_lines=1;
def= {'test1.txt',};
ts = inputdlg(prompt,dlg_title,num_lines,def);
%Now when i write ts in matlab command line I have %ts='test1.txt'
fid=fopen(ts)
RP=textscan(fid,'%*s %*s %s %*s %*s %s','delimiter',',');
fclose(fid);
but it seems that fopen does not work in this way and i should write the name of file in string format, but because i have to change the input file, what shall i do? and i have this message: ??? Error using ==> textscan First input can not be empty. Error in ==> testmeisam at 20 RP=textscan(fid,'%*s %*s %s %*s %*s %s','delimiter',',');
  1 件のコメント
Chandra Kurniawan
Chandra Kurniawan 2012 年 3 月 9 日
How do you format your text file?

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

採用された回答

Chandra Kurniawan
Chandra Kurniawan 2012 年 3 月 9 日
Hi,
ts is cell array.
please try
ts = cell2mat(ts);
after line
ts = inputdlg(prompt,dlg_title,num_lines,def);
  1 件のコメント
Meisam
Meisam 2012 年 3 月 9 日
thans alot, it works now

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by