Interval overlap not working

3 vues (au cours des 30 derniers jours)
Edoardo Modestini
Edoardo Modestini le 3 Mai 2023
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.

Réponse acceptée

Divyanshu
Divyanshu le 19 Mai 2023
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 commentaire
Edoardo Modestini
Edoardo Modestini le 27 Mai 2023
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

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by