Plotting peaks with different values of time on top of each other
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Taylor Parker
am 21 Jan. 2019
Beantwortet: Taylor Parker
am 22 Jan. 2019
I have a set of data that goes something like [0 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0 0 0 1 2 4 6 3 2 1 0 0 0 0 0 0] and so forth, making multiple bell shaped curves when plotted versus the time collecting it. I would like to plot those curves on top of each other, setting the time (x value) = 0 for each one.
When the data exceeds 1 (the nature of my if statement) I wish to index every value about 10 rows before it exceeds 1, and 10 rows after it drops below 1, so I can see the entire curve including the flat parts of these curves. Let me know if I can provide my code (relatively new to MatLab programming), as it is incorrect but a start. Thank you so much.
0 Kommentare
Akzeptierte Antwort
Matt Gaidica
am 22 Jan. 2019
Bearbeitet: Matt Gaidica
am 22 Jan. 2019
Taylor, to simplify, I would consider two options:
(1) Detect the threshold crossing (i.e., data >= 1) and plot a fixed amount of data points around that crossing. Just make that number large enough to encompass the curves you're investigating. This method keeps your data chunked into a square matrix. See below. You could use variable sizing, but you would have to pad your data segements.
data = [0 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0 0 0 1 2 4 6 3 2 1 0 0 0 0 0 0];
threshIdxs = find(diff(data > 1) == 1);
nPre = 3;
nPost = 10;
dataArr = zeros(nPre + nPost + 1,numel(threshIdxs));
for ii = 1:numel(threshIdxs)
dataArr(:,ii) = data(threshIdxs(ii) - nPre:threshIdxs(ii) + nPost);
end
figure;
plot(dataArr);
I have an instinct that getting the data into an array first might be helpful to you later on, so I did that before plotting.
(2) Detect the peaks in your data and align your curves around those peaks. Not knowing the nature of your problem, this may or may not be your intended goal. PeakSeek is a nice function to get started down that path.
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!