Storing elements to a matrix

2 visualizaciones (últimos 30 días)
Mohammad Juned
Mohammad Juned el 13 de Mzo. de 2021
Comentada: Mohammad Juned el 15 de Mzo. de 2021
Hi everyone. This my code
clc
clear all
m=[ 1 2 3; 4 5 6; 7 8 9];
c=1;
for k=1:3;
for f= 1:3;
m1(k,f)=(m(c+1,k)+m(c+2,f));
end
end
disp(m1);
for k=1:size(m,2)
M(:,:,k)=m(1,k)+m1;
end
disp(M);
the output of this code is
11 12 13
12 13 14
13 14 15
(:,:,1) =
12 13 14
13 14 15
14 15 16
(:,:,2) =
13 14 15
14 15 16
15 16 17
(:,:,3) =
14 15 16
15 16 17
16 17 18
>>
But I want to save all 27 values in a single matrix
how it can be done
  1 comentario
Sergey Kasyanov
Sergey Kasyanov el 13 de Mzo. de 2021
Hello, all 27 values are stored in 3-d dimensional matrix. If you want the 2-d matrix you should to describe what are you want in detail.

Iniciar sesión para comentar.

Respuesta aceptada

ANKUR KUMAR
ANKUR KUMAR el 15 de Mzo. de 2021
3D data can be converted to 2D using reshape. You just need to reshape your matrix based on your requirements.
A1=reshape(M,3,[],1);
Above code yields to 3 X 9 matrix.
A2=reshape(M,[],3,1);
Above code yields to 9 X 3 matrix.
A3=reshape(M,9,[],1);
Above code yields to 9 X 3 matrix.
A4=reshape(M,[],9,1);
Above code yields to 3 X 9 matrix.
A1 and A4 are identical, and A2 and A3 are identical.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by