MATLAB Answers

How to store vectores which have different lengts? (in a loop)

1 view (last 30 days)
IBM watson
IBM watson on 13 Dec 2018
Answered: madhan ravi on 13 Dec 2018
This doesnt work because every tupple have differents lengths :
for i=2:5
ar(i,:)=ones(1,q(i)-q(i-1)+2);
end
q is a random generated vector here.
What I intended to do is:
ar(2,:)=ones(1,q(2)-q(1)+2)
ar(3,:)=ones(1,q(3)-q(2)+2)
.
.
.

  0 Comments

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 13 Dec 2018
Store it as cell like below:
ar=cell(1,4);
for i=2:5
ar{i-1}=ones(1,q(i)-q(i-1)+2);
end
celldisp(ar)

  0 Comments

Sign in to comment.

More Answers (0)


Translated by