How to get intervals according to conditions of other parameters?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to analyze some data and I need to identify the intervals of certain parameters using the conditions of other parameters. For example, I need the intervals marked on the picture(vertical lines):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145582/image.png)
Conditions are: red increasing, dashdot is const, blue > ref value, black > ref value. Yellow represents someone else's attempt of doing this. Especially, I want to know how can I check for increasing/decreasing condition with cases where it sometimes const in between: small intervals in between where obj.red(i) = obj.red(i+1), which need to be included, but I want to avoid intervals like shown in the circle.
This is how I do it now:
%obj - instance of a class
i = 0;
eachInterval = [];
while (i < length (obj.dashdot))
i = i + 1;
if ( obj.blue(i) > ref...
% also sometimes there are small intervals in between
% where obj.red(i) = obj.red(i+1), which need to be included,
% but I want to avoid intervals like shown in the circle
&& obj.red(i) < obj.red(i+1)...
&& obj.dahsdot(i) == obj.dahsdot(i+1))
eachInterval(end+1) = i;
% make sure here (i+1)
if ( ~( obj.blue(i) > ref...
&& obj.red(i) < obj.red(i+1)...
&& obj.dahsdot(i) == obj.dahsdot(i+1)))
%
if (length(eachInterval) > 0)
obj.interStarts(end+1) = eachInterval(1);
obj.interEnds(end+1) = eachInterval(end);
eachInterval = [];
else
eachInterval = [];
end
end %if
end % if
end % while
Thanks, Nurlan.
0 个评论
回答(1 个)
SK
2014-10-2
编辑:SK
2014-10-2
Its a little tricky, unless you have a little more information. For example, do you know the number of increasing runs - call it N. Suppose you knew that N = 3, then use the
fit()
function with the 'linearinterp' fittype. You'll need to create a function that returns the y-coordinate of a piecewise linear function, given the parameters and x-coordinate. In your case the parameters will be the starting and ending points of the increasing segments. The fit() function will call your function with different trial parameter values and x-coordinates. See the matlab documentation for fit(). There is an example there.
This will work only for small values of N. For larger values, it may take too much time to run. However it is very robust and covers all those niggling issues of small constant segments and so on.
One you have the fit (purely based on the condition of increasing red), you can apply the other conditions to eliminate segments.
2 个评论
SK
2014-10-4
编辑:SK
2014-10-4
As you probably realized, the problem is not so easy. I've concluded that curve fitting is the most robust, but if you don't want to spend too much time on it, you could use some quick and dirty way. For this you will need to define some cutoff values. Some, possibly stupid, ideas:
idea 1:
1. Cutoff run length (r0). If run length < r0, then discard.
2. Cutoff average slope over length r0 (s0). If average slope over r0 is < s0, then discard.
3. Then move along the curve computing these two quantities at every point. If average slope > s0 for a run of at least r0, then you have an increasing interval.
---------
idea 2:
Take second differences. The take off point for an increasing interval will have a positive peak in the second derivative and landing point will have negative peak. Try to identify pairs of positive and negative peaks with condition that:
peak_height * distance_between_peaks > some_cutoff_value
which is supposed to ensure that it is a significant ramp. There may be pairs between pairs (just like opening and closing brackets) that you need to skip that are not significant. Also some take offs and /or landings may be slow and so may not have a very high peak - but perhaps such segments are best excluded anyway.
You may want to combine both these methods with some sort of prior smoothing on the curve.
In any case, the if's and but's for the quick and dirty methods are never-ending, so you cant be discouraged by that. Just test and see if it works for your particular type of data.
By the way, take these ideas with a pinch of salt. You may be able to come up with better ones.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!