Irregular Arrays for fixed.Interval Objects

5 views (last 30 days)
Hi,
I am working on code in which I am constructing an interval of valid inputs and I have been using fixed.Interval objects. My code involves taking the set difference between intervals and this is resulting in having irregular-sized objects in the following manner (example with basic numbers):
% Initial Valid Inputs
valid = fixed.Interval([1;3],[2;4])
valid =
[1,2] [3,4] 2x1 fixed.Interval with properties: LeftEnd RightEnd IsLeftClosed IsRightClosed
% Invalid Inputs
invalid = fixed.Interval([1.4;3.5],[1.6;4])
invalid =
[1.4000,1.6000] [3.5000,4] 2x1 fixed.Interval with properties: LeftEnd RightEnd IsLeftClosed IsRightClosed
% Valid Inputs in First Variable Once Removing Invalid
valid_hold1 = setdiff(valid(1),invalid(1))
valid_hold1 =
[1,1.4000) (1.6000,2] 1x2 fixed.Interval with properties: LeftEnd RightEnd IsLeftClosed IsRightClosed
% Valid Inputs in Second Variable Once Removing Invalid
valid_hold2 = setdiff(valid(2),invalid(2))
valid_hold2 =
[3,3.5000) 1x1 fixed.Interval with properties: LeftEnd: 3 RightEnd: 3.5000 IsLeftClosed: true IsRightClosed: false
Now, the issue is my two valid interval sets are 1x2 and 1x1 since in the one variable the valid inputs are now split into two intervals. As such the intervals can not be concatenated into a single fixed.Interval object in order to be returned. Of course, at such a small scale simply doing individual variables would be fine, but I need to expand it to an arbitrary number of variables. I thought of using a cell array, however fixed.Interval objects do not fit in cells. Does anyone have an idea on a way to solve this problem?

Accepted Answer

dpb
dpb on 22 Sep 2022
Never heard of them, but never used/don't have the FixedPoint TB ... all my micro work occurred way before any of these toolsets existed...
Anyways, not sure how you tried it and why concluded a cell array doesn't work, but at least the brute-force way seems to...
valid = fixed.Interval([1;3],[2;4]);
invalid = fixed.Interval([1.4;3.5],[1.6;4]);
% Valid Inputs Removing Invalid
valid_hold=arrayfun(@setdiff,valid,invalid,'uniform',0)
valid_hold = 2×1 cell array
{1×2 fixed.Interval} {1×1 fixed.Interval}
  1 Comment
Michael McCreesh
Michael McCreesh on 22 Sep 2022
I'm not sure exactly what I was doing to get an error, but that clearly works. Thanks!

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!