how to use sprintf
4 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have problems in defining the right format in sprintf. I want to enter subfolders with names defined in the n vector. I used sprintf('%1.1f', j*0.1) to define the name of the folder but it reads the folders like [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,...] and the problem is that my folder is named 1 and not 1.0. How to I specify it in the format of sprintf?
n = [0.1:0.1:120]';
for j=1:length(n)
folder = sprintf('%1.1f', j*0.1);
cd (folder);
end
thanks
回答 (1 件)
Jan
2013 年 7 月 17 日
But is this surprising? You multiply j by 0.1 and if j is 1 the resulting value is 0.1 .
You showed code, which does not work and ask for improvements. But you did not explain, what you want. So how could we suggest anything without guessing?
What about this guess:
for j = 1:120
folder = sprintf('%d', j);
cd(folder);
end
But this would mean, that you have a folder hierarchy like 1\2\3\4\5\...
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!