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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Sept. de 2011

1 voto

10 comentarios

mohammad
mohammad el 3 de Sept. de 2011
thanks let me check now
mohammad
mohammad el 3 de Sept. de 2011
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 el 3 de Sept. de 2011
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 el 3 de Sept. de 2011
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 el 3 de Sept. de 2011
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 el 3 de Sept. de 2011
and you are right Walter i dont need trying to make A1, A2
Walter Roberson
Walter Roberson el 3 de Sept. de 2011
fprintf('finished checking of input %d\n', i);
mohammad
mohammad el 3 de Sept. de 2011
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 el 3 de Sept. de 2011
speaker.Speak(sprintf('finished checking input %d', i));
mohammad
mohammad el 3 de Sept. de 2011
great, perfect!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by