Interval overlap not working

4 次查看(过去 30 天)
Hi,
I'm trying to create a Matlab file to carry out pinch analysis. As part of it, I'm checking whether certain streams are present in a temperature interval.
function check_present(obj)
%Loops through each interval
for i = 1:length(obj.intervals)
%Creating "present" and "present names"
present = [];
present_names = [];
for k = 1:length(obj.streams)
%Checking if the ranges of the shifted temperatures
%overlap with the range of the stream temps, I think.
%Clearly, this bit is not working since it outputs the
%wrong thing.
if overlaps(fixed.Interval(obj.streams(k).Sin, obj.streams(k).Sout), fixed.Interval(obj.intervals(i).Tlow, obj.intervals(i).Thigh, '()'))
present = [present; obj.streams(k)];
present_names = [present_names; obj.streams(k).name];
end
end
obj.intervals(i).present = present;
obj.intervals(i).present_names = present_names;
This, however, is not doing what it's meant to, and is outputting the wrong streams in each interval. The matlab files are attached in case not enough information is given here!
Thanks in advance for any help.

采纳的回答

Divyanshu
Divyanshu 2023-5-19
Hi Edoardo,
The reason why your function check_present is displaying wrong values is because ‘fixed.Interval()’ function only generates interval when 1st argument passed to this function is lower in range then the 2nd one.
For e.g. -> fixed.Interval(2,8) would produce interval with Left-End ‘2’ & Right-End ‘8’.
But in the case fixed.Interval(7,1) it would produce an empty interval.
And according to the data being used in your scripts there are certain instances where streams like 'Sin' = 390 & 'Sout' = 110 are generated. Hence in such cases function gives wrong output.
Here is a possible workaround to deal with such cases:
function check_present(obj)
%Loops through each interval
for i = 1:length(obj.intervals)
%Creating "present" and "present names"
present = [];
present_names = [];
for k = 1:length(obj.streams)
leftStr = min(obj.streams(k).Sin,obj.streams(k).Sout);
rightStr = max(obj.streams(k).Sin,obj.streams(k).Sout);
streamCur = fixed.Interval(leftStr,rightStr);
intervalCur = fixed.Interval(obj.intervals(i).Tlow, obj.intervals(i).Thigh,'()');
if overlaps(streamCur,intervalCur)
present = [present; obj.streams(k)];
present_names = [present_names; obj.streams(k).name];
end
end
obj.intervals(i).present = present;
obj.intervals(i).present_names = present_names;
end
end
For further details on ‘fixed.Interval()’ function refer the following documentation:
  1 个评论
Edoardo Modestini
Edoardo Modestini 2023-5-27
Hi,
Thank you! I somehow didn't catch this in the documentation / didn't think that my values would sometimes be backwards. This fixed it!
Edoardo

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by