How to save vectors with different lengths in a matrix?

4 ビュー (過去 30 日間)
Kevin Paapst
Kevin Paapst 2018 年 4 月 30 日
コメント済み: Ameer Hamza 2018 年 4 月 30 日
For research project I want to calculate damping factor of a oscillation, that occur multiple times over time. With the wavetimecheck, I compute the time of the wave 1,2,3... were in the oscillations occur. with peakdet I find the peaks of the force and time. from the plot i can see that there are 5 peaks, so I let it run to n=4. Fist i forget to save the values of timeup1 forceup1, so I calculated only one dampingfactor. Now I want to save these values in a matrix, but these wavetimes differ, so the length of the vectors "timeup" and "forceup" of oscillation 1 and oscillation 2 are different. So I want to save these vectors in 1 matrix, I think that is the most handy way to calculate the damping factor. Or is there a more easy way?
This is the code I wrote.
for m = 1:30
timeup = wavetime_check(m,1):wavetime_check(m,2);
MATtime(m,:) = timeup;
format long
forceup = (force_filt((wavetime_check(m,1)):(wavetime_check(m,2))).');
MATforce(m,:)= forceup
[maxtab, mintab] = peakdet(forceup, 0.0000001, timeup);
for n = 1:4 % heeft 5 peak dus n tot 4.
logdec (n) = log(maxtab(n,2)/maxtab((1+n),2))
end
Mean_logdec = mean(logdec)
Zeta= Mean_logdec/sqrt(4*(pi)^2 + (Mean_logdec)^2)
end

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 4 月 30 日
編集済み: Ameer Hamza 2018 年 4 月 30 日
You cannot use a matrix to store vectors of varying length. For that, you will need to use a cell array. Use it as follow.
timeupMatrix{m} = timeup;
forceupMatrix{m} = forceup;
You can access them using timeupMatrix{1}, timeupMatrix{2} notation.
  2 件のコメント
Kevin Paapst
Kevin Paapst 2018 年 4 月 30 日
Ahh thankyou! That part works now! Now I think I have a similar problem. I changed my code and to compute the peaks i know have:
[maxtab, mintab] = peakdet(MATforce{m}, 0.00000007, MATtime{m})
It computes/find now all the peaks, but only saves the last values of the peaks, for m=30, and so only calculates the damping factor for m=30.
How can I save the values of [maxtab,mintab] also in an cell array?
Ameer Hamza
Ameer Hamza 2018 年 4 月 30 日
You can use
[maxtab{m}, mintab{m}] = peakdet(MATforce{m}, 0.00000007, MATtime{m})

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by