how to use sprintf
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposte (1)
Jan
il 17 Lug 2013
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 Commenti
Vedere anche
Categorie
Scopri di più su Entering Commands in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!