# How to save vectors with different lengths

6 views (last 30 days)
Chinh Le Trung on 29 Mar 2019
Commented: Guillaume on 30 Mar 2019
Here is the problem: A crack has Weibull distribution and each month it increase by deltaL in length. I have to plot 100 different lines with different quantity of elements in vector because it is random. I can only save one vector at a time. But I want to save all 100 vectors with different lengths into 1 matrix and use that matrix to plot 100 lines.
This is my code:
beta = 1.5;
alpha = 1;
l = 0;
k = 1;
while l < 100
k = k+1;
t= 1:k;
deltaL(k) = wblrnd(alpha,beta);
if k == 1
l(k) = deltaL(k);
else
l(k) = l(k-1) + deltaL(k);
end
end
plot(t,l);
Guillaume on 30 Mar 2019
"As far as I know,f logical vector is true then the loop continues"
When is a logical vector true? Is the logical vector [true, false, true] true? What about the logical vector [false, true, false]?
Remember that when l is a vector, e.g. [1 2 3 4 5], l<100 will return a logical vector, in this case [true, true, true, true, true].

Catalytic on 29 Mar 2019
Edited: Catalytic on 29 Mar 2019
One way is to use cell arrays
C={1,[2,3],[4,5,6,7]}