How do you append to a matrix within a for loop when the matrices are unequal in size?
1 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
James Tursa
2019-8-29
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 个评论
Steven Lord
2019-8-29
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!