Find Function in Matlab

조회 수: 3 (최근 30일)
Karoline Qasem
Karoline Qasem 2016년 10월 23일
댓글: Karoline Qasem 2016년 10월 24일
hello,
I have say:
X=[0 1 0 0 2 0 0 0 0 0 4];
Y=[5 2 5 5 1 3 2 5 5 5 5];
somehow, Y is depending on X and whenever X is greater than 0, Y drops down. I am interested in seeing how many time steps does it take Y to go to its average value after each peak of X. In other words, I need to search for when is Y(i-1) = Y(i+a)+-10%
where i-1 is the day before X peak.
Example:
the first peak of X is 1
the day before it is where Y was 5
it looks like it took Y one time step to go back to this 5 after the peak of X
I hope I am clear in the question and really need help.
Thanks

채택된 답변

Guillaume
Guillaume 2016년 10월 23일
This should work:
xpeaks = find(X);
assert(xpeaks(1) ~= 1, 'Peak on first value, can''t go back before peak');
delay = arrayfun(@(peakloc) find(abs(Y(peakloc:end) - Y(peakloc-1)) <= Y(peakloc-1)/10, 1) - 1, xpeaks)
  댓글 수: 3
Guillaume
Guillaume 2016년 10월 24일
I would suspect that it is because Y never gets to within 10% of value just before the 12th peak, therefore find returns empty.
As per the error message set 'UniformOutput' to false in arrayfun so that it creates a cell array output (in order to be able to contain empty elements:
delay = arrayfun(@(peakloc) find(abs(Y(peakloc:end) - Y(peakloc-1)) <= Y(peakloc-1)/10, 1) - 1, ...
xpeaks, 'UniformOutput', false);
If you want, you can convert those empty elements into NaNs to get a matrix output:
delay(cellfun(@isempty, delay)) = {NaN}; %replace empty by NaN
delay = cell2mat(delay);
Karoline Qasem
Karoline Qasem 2016년 10월 24일
Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 10월 23일
Try this:
X = [0 1 0 0 2 0 0 0 0 0 4]; % Not used.
Y = [5 2 5 5 1 3 2 5 5 5 5] % Our data.
% Find non-5 locations.
binaryVector = Y ~= 5
% Give an ID number to each non-5 region.
labeledVector = bwlabel(binaryVector);
% Measure the lengths of those regions.
% Requires the Image Processing Toolbox.
props = regionprops(labeledVector, 'Area');
% Compute the number of steps to return to 5
% once it has dropped down to a lower value:
numSteps = [props.Area]
% Get the mean of those numbers
meanStepCount = mean(numSteps)
You'll see:
Y =
5 2 5 5 1 3 2 5 5 5 5
binaryVector =
1×11 logical array
0 1 0 0 1 1 1 0 0 0 0
numSteps =
1 3
meanStepCount =
2
  댓글 수: 5
Image Analyst
Image Analyst 2016년 10월 23일
You can compute the difference from the prior value with diff
diffy = diff(y);
I'm not sure what value it must achieve until it's restored again. Is it the value right before it dipped?
Karoline Qasem
Karoline Qasem 2016년 10월 23일
yes, i am looking for the value close to the one prior to the peak. I am sorry for not being clear, just my data is very noisy and hard to deal with since i am beginner to matlab.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by