How to find peaks in a for loop where the number of peaks are not the same for every vector in matrix?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Kimberly Cardillo
il 9 Giu 2020
Commentato: Jiri Hanacek
il 20 Gen 2022
I am trying to find the peaks and locations of vectors in the columns of a matrix (CH1WaveForm_1). Not every vector has the same number of peaks and I think thats why it is giving me this error: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
for i=1:size(CH1WaveForm_1,2)
QT(:,i) = [CH1WaveForm_1(1:end,i)];
[pks(i),locs(i)]=findpeaks(QT(:,i));
end
I keep getting that error and I have tried changing the last line to [pks(:,i),locs(:,i)]=findpeaks(QT(:,i)); and it still does not work. Is there any way to make this work without having to write the individual lines of code for the entire matrix? The matrix is 5119 x 102.
0 Commenti
Risposta accettata
dpb
il 9 Giu 2020
That's when cell arrays are useful...
for i=1:size(CH1WaveForm_1,2)
[pks{i},locs{i}]=findpeaks(CH1WaveForm_1(1:end,i));
end
2 Commenti
Jiri Hanacek
il 20 Gen 2022
I have spent whole the afternoon on this problem,
thinking that I am absolutely silly and will never find the solution.
Thanks a lot for your tip!
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!