Interval overlap not working
1 次查看(过去 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.
0 个评论
采纳的回答
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:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!