need help for take data from loop

1 visualización (últimos 30 días)
christiano doni
christiano doni el 6 de Abr. de 2015
Comentada: christiano doni el 6 de Abr. de 2015
I have scrip data like this
clear all;close all;clc
c1=imread('1200TIM-20150401-0010_20150401-1054015001500-1','png');
a1=double(c1);
a1=reshape(a1,2229000,[]);
c2=imread('1200TIM-20150401-0020_20150401-1054015001500-1','png');
a2=double(c2);
a2=reshape(a2,2229000,[]);
c3=imread('1200TIM-20150401-0030_20150401-1054015001500-1','png');
a3=double(c3);
a3=reshape(a3,2229000,[]);
and I have matrix
a1=(2229000,3); a2=(2229000,3); a3=(2229000,3);
and i want to make 3 matrix data like this
red=[a1(:,1),a2(:,1),a3(:,1)]
green=[a1(:,2),a2(:,2),a3(:,2)]
blue=[a1(:,3),a2(:,3),a3(:,3)]
*my questions is how to make loop for red, grean and blue because data a1, a2 until a100, i try *
for i=1:1:3; red(:,i)=['a'num2str(i)(:,1)]; end
but its not working here

Respuesta aceptada

Philipp Maier
Philipp Maier el 6 de Abr. de 2015
Editada: Philipp Maier el 6 de Abr. de 2015
The eval function can be used to execute the MATLAB expression. For example:
for i=1:1:3;
red(:,i)= eval(['a' num2str(i) '(:,1)'])';
end
Since I do not have the PNG-files that you are reading , I tested the code with three random variables:
a1 = rand(2229000,3);
a2 = rand(2229000,3);
a3 = rand(2229000,3);
  1 comentario
christiano doni
christiano doni el 6 de Abr. de 2015
ah ...thank you sir...it's working here

Iniciar sesión para comentar.

Más respuestas (1)

Jan
Jan el 6 de Abr. de 2015
No, do not do this. It might work in this specific case, but it is in general an evil method and it produces more troubles than it solves. The problem is discussed several times a day and therefore you find it in the frequently asked questions also: http://www.mathworks.com/matlabcentral/answers/57445-faq-how-can-i-create-variables-a1-a2-a10-in-a-loop .
  1 comentario
christiano doni
christiano doni el 6 de Abr. de 2015
ok sir, move to you link.. thanks for you advice

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by