필터 지우기
필터 지우기

How to make script to function for sprintf command

조회 수: 1 (최근 30일)
Nopparat
Nopparat 2012년 9월 6일
I want to write this make this script to function
name = regexp(sprintf('test%.3d.tif*',0:10 ), '*', 'split');
I got the result "test000, test001, test002, ..., test010" so I worked Then I want to make it to function so I did
function filename(basename, digits, start_no)
name = regexp(sprintf('basename %.digits d.tif*', start_no:10-start_no-1), '*', 'split');
end but it didn't work so I use %s
function filename(basename, digits, start_no)
name = regexp(sprintf('%s %. %s d.tif*', start_no:10-start_no-1, basename, digits), '*', 'split');
It still didn't work so how can I fix it. Thank you in advance
  댓글 수: 2
Matt Fig
Matt Fig 2012년 9월 6일
Please learn to format your posts, and be more descriptive. What does "it doesn't work" mean? Did MATLAB crash? Did you get an error message (what did it say?)? Did the computer catch fire? Be specific!
Walter Roberson
Walter Roberson 2012년 9월 6일
It would be less error-prone to use '\*' in the pattern instead of '*'.

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

채택된 답변

Matt Fig
Matt Fig 2012년 9월 6일
There are several problems. For one, you don't specify any return argument for your function. Try this one:
function name = filename(basename, digits, start_no)
S = sprintf('%i',digits);
S = sprintf([basename, '%.',S,'d.tif*'], start_no:10-start_no-1);
name = regexp(S(1:end-1), '*', 'split');
Now at the command line:
filename('test', 7, 0)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by