How to get value from string II = strcat('A', num2str(la));

3 visualizaciones (últimos 30 días)
Ole
Ole el 11 de Mzo. de 2016
Editada: Stephen23 el 19 de Jun. de 2019
I want to plot few matrices A1 A2 A3 A4 A5 and call them in loop to make a movie. I am trying to make a string II = strcat('A', num2str(la)); but I can not get the values of the previously defined A1 matrix ?
The code below returns an error that II must be a matrix but is string A1 with no values.
A1 = rand(10,10); A2 = rand(10,10); A3 = rand(10,10); A4 = rand(10,10); A5 = rand(10,10);
for la = 1 : 5
II = strcat('A', num2str(la));
pcolor(II)
shading interp
end
  1 comentario
Stephen23
Stephen23 el 12 de Mzo. de 2016
Editada: Stephen23 el 19 de Jun. de 2019
And note that you should not create numbered variables and then try to loop over them. Put all of your data into one variable (an ND array perhaps) and then loop over the dimensions of that array.
The idea of looping over separate numbered variables often occurs to beginners, but this is a slow, buggy, and obfuscated way to code:

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 11 de Mzo. de 2016
pcolor takes numbers, not character arrays, so why are you trying to create a character array?
And did you know that pcolor does not show you the last row or column? Use imshow instead
wideImage = [A1,A2,A3,A4,A5];
imshow(wideImage, []);
No for loop needed at all.
  2 comentarios
Ole
Ole el 11 de Mzo. de 2016
Thanks. This displays 5 matrices next to each other. How can be used to plot in a video one A matrix at a time ?
Image Analyst
Image Analyst el 11 de Mzo. de 2016
If you want a video of this, you'll have to make up an image first. Then use text() to display text over the image. Then use VideoWriter to write the image frames to a video file, like in the attached example.

Iniciar sesión para comentar.


Stephen23
Stephen23 el 12 de Mzo. de 2016
Editada: Stephen23 el 19 de Jun. de 2019

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by