Find Function in Matlab
Show older comments
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
Accepted Answer
More Answers (1)
Image Analyst
on 23 Oct 2016
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 Comments
Karoline Qasem
on 23 Oct 2016
Image Analyst
on 23 Oct 2016
Do you want to compare to 10% different than prior value, or "average" value. And how are you computing average value? Do you consider dips when computing the average, if so they would decrease the average. Maybe you want outlier detection or median absolute deviation or something.
Karoline Qasem
on 23 Oct 2016
Edited: Karoline Qasem
on 23 Oct 2016
Image Analyst
on 23 Oct 2016
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
on 23 Oct 2016
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!