How to assign values to a variable size array
이전 댓글 표시
The following works fine
k=[];
for jj=1:10
k(jj,:)=randi(10,1,3);
end
However, I'm facing difficulties when I try to assign different rows' elements to variable size array k:
k=[];
for jj=1:10
k(1,:)=randi(10,1,jj);
end
I would appreciate your help.
댓글 수: 6
Walter Roberson
2021년 2월 21일
Arrays cannot have different number of elements per row or column.
Asaf McRock
2021년 2월 21일
KALYAN ACHARJYA
2021년 2월 21일
Are you considering this
k=[];
for jj=1:10
k=[k,randi(10,1,jj)];
end
Or
For rows or column vectors of different lengths, you can save the data in a cell array.
Asaf McRock
2021년 2월 21일
N = 10;
k = cell(N,1);
for jj = 1:N
k{jj} = randi(10,1,jj);
end
k
Asaf McRock
2021년 2월 21일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!