Mostrar comentarios más antiguos
i have G={[1 0 1;1 0 0;0 0 1;1 1 1] and out put should be I={[1 0;1 0; 0 0;1 1]} how can i get
using for loop
1 comentario
Fangjun Jiang
el 23 de Jul. de 2011
Not sure if you understand the meaning of {} in MATLAB. It is used to reference cell array. Your example data indicates no need of it. Please do not use it unnecessarily because it might confuse readers regarding your data structure.
Respuesta aceptada
Más respuestas (1)
Fangjun Jiang
el 23 de Jul. de 2011
Assume the element in I is the first two columns of the element in G.
G=[1 0 1;1 0 0;0 0 1;1 1 1];
[M,N]=size(G);
I=zeros(M,2);
for k=1:size(G,1)
I(k,:)=G(k,1:2);
end
Without for-loop, you can do.
I=G(:,1:2)
2 comentarios
Andrei Bobrov
el 23 de Jul. de 2011
for j1 = 1:size(I,2)
I(:,j1) = G(:,j1);
end
Daniel Shub
el 23 de Jul. de 2011
and I am giving a +1 to Fanqjun since he (assuming he) gave the same answer, and typed faster than me.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!