How to assign values to a variable size array

10 Ansichten (letzte 30 Tage)
Asaf McRock
Asaf McRock am 21 Feb. 2021
Kommentiert: Asaf McRock am 21 Feb. 2021
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 Kommentare
Walter Roberson
Walter Roberson am 21 Feb. 2021
N = 10;
k = cell(N,1);
for jj = 1:N
k{jj} = randi(10,1,jj);
end
k
k = 10x1 cell array
{[ 6]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double}
Asaf McRock
Asaf McRock am 21 Feb. 2021
Thank you, gentlemen!
I'm learning so much from you. Much appreciated!

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by