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 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!