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
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 件のコメント
Krish Gupta
Krish Gupta 2019 年 8 月 29 日
Thanks a lot
Steven Lord
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 ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by