finding prominent maxima and minima of a column vector
Mostra commenti meno recenti
Hello,
Suppose I Have a column vector wcich has multiple maxima and minima, I just want to find the index of N= 4 number of them ( prominent maxia and minima).
And if I use something like 'findpeak' then it gives a lots of local max and min as for a noisy signal. I want to get the prominant max & min indices of the 2nd colm of the attachment please.
Thank you
Risposta accettata
Più risposte (1)
az
il 21 Giu 2019
0 voti
9 Commenti
Star Strider
il 21 Giu 2019
Try this:
idxv = sort([plocs; vlocs]); % Concatenate Peak & Valley Vectors & Sort Ascending
for k = 1:numel(idxv)-1
Segments{k} = D(idxv(k):idxv(k+1),2); % Store Data Between Indices
end
That should do what you want. Note that it begins from the first valley, and stores to the next peak, then stores to the next valley ... until it finished. Here, there are 7 segments total.
az
il 21 Giu 2019
Star Strider
il 22 Giu 2019
As always, my pleasure.
To do that, simply change the ‘Segments’ assignment to:
Segments{k} = D(idxv(k):idxv(k+1),:);
That captures both columns.
az
il 22 Giu 2019
Star Strider
il 22 Giu 2019
The index values shouldn’t enter into it.
This works for me, and the data have the same x-values as the original data (I checkled):
figure
hold all
for k = 1:numel(Segments)
plot(Segments{k}(:,1), Segments{k}(:,2))
end
hold off
grid
Compare with:
figure
plot(D(:,1), D(:,2))
They are the same.
az
il 22 Giu 2019
Star Strider
il 22 Giu 2019
‘is there any I can save the individual data segments as a 'double' or 'table' instead of 'cell'’
You can convert them to individual double matrices, or to tables if you like. The problem is that they contain different numbers of elements, so you can’t concatenate them into a 3D array, for example. You could use the cell2mat function to save each ‘Segments’ cell as a separate matrix, however this makes for very inefficient code when you go to use them later.
With respect to the plots, I am still not certain what you want.
Try these:
figure
hold all
for k = 1:numel(Segments)
plot(Segments{k}(:,1)-Segments{k}(1,1), Segments{k}(:,2))
end
hold off
The first loop plots the individual segments.
figure
hold all
for k = 1:2:numel(Segments)-1
plot(Segments{k}(:,1)-Segments{k}(1,1), Segments{k}(:,2))
plot(Segments{k+1}(:,1)-Segments{k}(1,1), Segments{k+1}(:,2))
end
plot(Segments{end}(:,1)-Segments{end}(1,1), Segments{end}(:,2))
hold off
The second loop plots them as complete waveforms, with the respective ascending and descending segments linked.
Both of these should also give you a good idea of how to address the ‘Segments’ cells.
az
il 22 Giu 2019
Star Strider
il 23 Giu 2019
As always, my pleasure.
‘So in capacity3.m I omit those data points manually from line 19th to 26.’
There are several way to do this, one is to completely eliminate them by setting that range equal to the empty array [], another is to set them equal to NaN. What you do depends on the result you want.
I ran your code, and it seems to do what you want. There are several connecting lines that appear strange to me (they do not appear on the plots my code produces), however looking at your plot calls, you added them specifically, so they are not artefacts.
I do not understand what you want to do, especially with respect to adding more for loops. I encourage you to experiment to get your code to do what you want it to.
Categorie
Scopri di più su Descriptive Statistics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!