Plotting peaks with different values of time on top of each other
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matt Gaidica
2019-1-22
编辑:Matt Gaidica
2019-1-22
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 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!