フィルターのクリア

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)
  1 件のコメント
Nopparat
Nopparat 2012 年 9 月 9 日
It works very well! Thank you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by