필터 지우기
필터 지우기

Introducing element * in sprintf()

조회 수: 1 (최근 30일)
Dimitris M
Dimitris M 2012년 7월 19일
Hello
I am trying to introduce the element * to the function sprintf in MATLAB.
My code look like this
ss=sprintf('%s//Segments//Image_TrueColor_%d',Pathname,*)
I could set the code to read in the names of the files at the point of the unknow number name but is it possible just to introduce the * (select all) command ?
Thank you in advance

답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 19일
That is not really a question about sprintf(), that is a question about the routine that you are using the resulting string. sprintf() just does string creation based upon the parameters passed to it, and it has no knowledge of files.
prefix = fullfile(Pathname, 'Segments');
fileinfo = fullfile( prefix, 'Image_TrueColor_*' );
filenames = strcat( prefix, {fileinfo.name} );
The result would be cell array of strings, one (complete) file name per entry.
For most operations you would then need to loop over those file names. Very few of the routines can operate on multiple files at the same time.
  댓글 수: 2
Dimitris M
Dimitris M 2012년 7월 19일
Hello
Thank you for your guidance but maybe my question was not very clear. The '*' is supposed to be a number that I do not know.
Your code works fine up to the point of
fileinfo = fullfile( prefix, 'Image_TrueColor_*' );
The things is that is should read something like
'Image_TrueColor_10' but it reads 'Image_TrueColor_*' which does not exist.
MATLAB returns
Attempt to reference field of non-structure array.
Can you guide me from this point ?
Thank you in advance !
Walter Roberson
Walter Roberson 2012년 7월 19일
Sorry, should have been
fileinfo = dir( fullfile( prefix, 'Image_TrueColor_*' ) );

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

카테고리

Help CenterFile Exchange에서 File Name Construction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by