MATLAB how to automatically read a number of files
5 ビュー (過去 30 日間)
古いコメントを表示
I would like to plot a number of 3D graphs from different data files. For example I am using
fid = fopen('SS 1.dat','r');
to read the first file and then plot a graph. How to set the program to change the name to 'SS 2.dat' automatically? Also for the tenth file the name becomes 'SS 10.dat' which has one space less (i.e.only two space between SS and 10) then the first to ninth files. How to set the program to adjust for that? Thank you.
0 件のコメント
回答 (1 件)
Stephen23
2015 年 10 月 29 日
編集済み: Stephen23
2015 年 10 月 30 日
This is a very common question, so we covered it very thoroughly in our wiki:
Because the files already exist I would recommend that you use the dir method, rather than trying to recreate the filenames using sprintf. You can use my FEX submission to sort the filenames correctly:
Or alternatively using sprint you can adapt this for your code:
>> fmt = 'SS%4d.dat';
>> sprintf(fmt,9)
ans = SS 9.dat
>> sprintf(fmt,10)
ans = SS 10.dat
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Printing and Saving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!