필터 지우기
필터 지우기

Interval overlap not working

조회 수: 2 (최근 30일)
Edoardo Modestini
Edoardo Modestini 2023년 5월 3일
댓글: Edoardo Modestini 2023년 5월 27일
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개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by