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!