Plotting peaks with different values of time on top of each other

2 ビュー (過去 30 日間)
Taylor Parker
Taylor Parker 2019 年 1 月 21 日
回答済み: Taylor Parker 2019 年 1 月 22 日
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.

採用された回答

Matt Gaidica
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.

その他の回答 (1 件)

Taylor Parker
Taylor Parker 2019 年 1 月 22 日
Hi Matt, this is very helpful. Thank you so much. That second function PeakSeek is a great idea. While googling that function I came across your neural electrophysiology work, I'm going to send you an email shortly.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by