How to save vectors with different lengths in a matrix?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kevin Paapst
am 30 Apr. 2018
Kommentiert: Ameer Hamza
am 30 Apr. 2018
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
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 30 Apr. 2018
Bearbeitet: Ameer Hamza
am 30 Apr. 2018
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 Kommentare
Ameer Hamza
am 30 Apr. 2018
You can use
[maxtab{m}, mintab{m}] = peakdet(MATforce{m}, 0.00000007, MATtime{m})
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!