how to use sprintf

7 Ansichten (letzte 30 Tage)
Hale
Hale am 17 Jul. 2013
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 Kommentar
Azzi Abdelmalek
Azzi Abdelmalek am 17 Jul. 2013
What are the names of your folders?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 17 Jul. 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\...

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by