convert a variable parameter to 'string' in matlab

does anyone know how can a variable parameter convert to string? for example in under case, i parameter, (that, is a variable parameter) needs to be a variable string:
for i=1:10
lable=['input'''' i ''' ];
[r,'''i''']=xlsread(lable);
end
that i want to read input1 , input2,....,input10 and put them respectively r1,r2,..,r10

 採用された回答

Walter Roberson
Walter Roberson 2011 年 9 月 3 日

1 投票

10 件のコメント

mohammad
mohammad 2011 年 9 月 3 日
thanks let me check now
mohammad
mohammad 2011 年 9 月 3 日
i studied sprintf and eval, sorry i am beginner in Matlab, why matlab errores for :sprintf('A%d', i)=sprintf('xlsread(lableinput%d)', i)
this is for
A1=(input1.xls)
A2=(input2.xls)
.
.
.
.
.
Walter Roberson
Walter Roberson 2011 年 9 月 3 日
Don't Do That!
basename = 'labelinput';
for i = 1:10
A{i} = xlsread(sprintf('%s%d.xls', basename, i));
end
Then use A{1} instead of A1, A{2} instead of A2, and so on.
What you are trying to do in making A1, A2, and so on, almost always runs in to problems.
mohammad
mohammad 2011 年 9 月 3 日
so nice, perfect
now i need in every loop it shows : fprintf(' finished checking of input' 'i')
for example after A1=input1.xls shows:finished checking of input1
and after A2=input2.xls shows:finished checking of input2
but i dont know how putting variable (i), in fprintf
mohammad
mohammad 2011 年 9 月 3 日
i mean this:
for i = 1:10
A{i} = xlsread(sprintf('%s%d.xls', basename, i));
fprintf(' finished checking of input' 'i')
end
mohammad
mohammad 2011 年 9 月 3 日
and you are right Walter i dont need trying to make A1, A2
Walter Roberson
Walter Roberson 2011 年 9 月 3 日
fprintf('finished checking of input %d\n', i);
mohammad
mohammad 2011 年 9 月 3 日
so thanks Walter
you really give a lot helps
for last question:
how can put variable in this speech:
NET.addAssembly('System.Speech');
speaker = System.Speech.Synthesis.SpeechSynthesizer();
speaker.Rate = 1;
speaker.Volume = 100;
speaker.Speak(['finished checking input'''i'''']);
Walter Roberson
Walter Roberson 2011 年 9 月 3 日
speaker.Speak(sprintf('finished checking input %d', i));
mohammad
mohammad 2011 年 9 月 3 日
great, perfect!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by