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

1 vue (au cours des 30 derniers jours)
IBM watson
IBM watson le 13 Déc 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)
.
.
.

Réponse acceptée

madhan ravi
madhan ravi le 13 Déc 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)

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by