How to save vectors with different lengths

2 次查看(过去 30 天)
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 个评论
Chinh Le Trung
Chinh Le Trung 2019-3-30
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 2019-3-30
"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].

请先登录,再进行评论。

回答(1 个)

Catalytic
Catalytic 2019-3-29
编辑:Catalytic 2019-3-29
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!

Translated by