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

조회 수: 2 (최근 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.

채택된 답변

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by