How do you append to a matrix within a for loop when the matrices are unequal in size?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Krish Gupta
el 29 de Ag. de 2019
Comentada: Steven Lord
el 29 de Ag. de 2019
N=input("How many matrices you want to enter?")
D1=[];
for a=1:N
m=input(' give the no. of columns:')
n=input(' give the no. of rows:')
for i=1:n
for j=1:m
C(i,j)=input("Give a number:")
end
end
D1=[D1;C]
end
% I want to get the two matrices, as input,[1 2;3 4] and [5 7 8; 6 9 10] stored in another array
%MY program above takes the input for the two matrices
% I want to store those two input matrices in some data type
% Suggest me how to do it
% the last line for D1 shows error for uneuqual sized matrices while it works for equal sized matrices
Respuesta aceptada
James Tursa
el 29 de Ag. de 2019
Maybe you could use a cell array. E.g.,
:
D1 = cell(1,N);
for a=1:N
:
D1{a} = C;
end
Then the first matrix is D1{1}, the second matrix is D1{2}, etc.
2 comentarios
Steven Lord
el 29 de Ag. de 2019
FYI, I deleted Krish Gupta's flag indicating that the answer worked well.
Please use flags for indicating that a comment or answer is unclear, not appropriate, or is spam. Use comments to offer thanks, to make follow-up requests on the same issue, or to provide additional information (such as when someone asks for clarification.) Thanks.
Más respuestas (0)
Ver también
Categorías
Más información sobre Multidimensional Arrays 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!