How to save vectors with different lengths

6 views (last 30 days)
Chinh Le Trung
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);
  5 Comments
Chinh Le Trung
Chinh Le Trung on 30 Mar 2019
Oh yes, I'm totally wrong about "if k == 1" and "t= 1:k". But k is not a constant value, because the variable "deltaL" follows Weibull distribution and k is the number of times when the variable "l" reaches 100 meters in length. Tks for your help!
Guillaume
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].

Sign in to comment.

Answers (1)

Catalytic
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]}

Community Treasure Hunt

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

Start Hunting!