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

 Accepted Answer

10 Comments

thanks let me check now
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)
.
.
.
.
.
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.
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
i mean this:
for i = 1:10
A{i} = xlsread(sprintf('%s%d.xls', basename, i));
fprintf(' finished checking of input' 'i')
end
and you are right Walter i dont need trying to make A1, A2
fprintf('finished checking of input %d\n', i);
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'''']);
speaker.Speak(sprintf('finished checking input %d', i));

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!