How to save vectors with different lengths

조회 수: 6 (최근 30일)
Chinh Le Trung
Chinh Le Trung 2019년 3월 29일
댓글: Guillaume 2019년 3월 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