フィルターのクリア

MATLAB how to automatically read a number of files

4 ビュー (過去 30 日間)
Kelvin
Kelvin 2015 年 10 月 29 日
編集済み: Stephen23 2015 年 10 月 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.

回答 (1 件)

Stephen23
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

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by