Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

matrix convertion and reconvertion

2 visualizaciones (últimos 30 días)
Raza Ali
Raza Ali el 2 de Mzo. de 2014
Cerrada: Azzi Abdelmalek el 2 de Mzo. de 2014
I want to move the matrix elements as desired like
a=[1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16]
now i want to make a into b
b=[3 4 8 7;
11 12 16 15;
14 13 9 10;
6 5 1 2]
how can i do it in MATLAB and how can i convert b back into a?

Respuestas (2)

David Young
David Young el 2 de Mzo. de 2014
To convert a into b, you can write
b(1,1) = a(1,3);
b(2,1) = a(3,3);
...
and so on. To convert back, use
a(1,3) = b(1,1);
a(3,3) = b(2,1);
...
and so on.
I suspect that perhaps you want something more concise. If so, please explain the rule that you are using, as I can't reliably infer it from the example.

Azzi Abdelmalek
Azzi Abdelmalek el 2 de Mzo. de 2014
Editada: Azzi Abdelmalek el 2 de Mzo. de 2014
a=[1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16]
b=a(:,3:4);
c=a(:,1:2);
b(2:2:end,:)=fliplr(b(2:2:end,:));
c=flipud(c);
c(1:2:end,:)=fliplr(c(1:2:end,:));
d=[b' c'];
out=reshape(d(:),size(a,2),[])'

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by