how to use sprintf

조회 수: 6 (최근 30일)
Hale
Hale 2013년 7월 17일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 17일
What are the names of your folders?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
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\...

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by