How to do Subtraction on sets?
5 ビュー (過去 30 日間)
古いコメントを表示
I have a continuous set (A=[0 , 2pi]) and want to subtract the following sets from it:
B= [0, pi/2];
C=[pi/4, pi];
D=[3pi/2, 7pi/4];
...
In general, I could just build the union of "B, C, ..." and then do the subtraction BUT I have to do this process a lot of times. In other words, the whole process is in a "for loop" and each time some sets need to be subtracted from A (each time the number of sets and their length is not necessarily might change). The initial interval (A) is the same for all the iterations (after each iteration I would get an interval corresponding to that iteration: Answer(i) = A - B(i) - C(i) -...).
I found a function in MATLAB called "setdiff" but it seems to only work on discrete intervals or images (I mean a 2D matrix)!
Is there a similar function for continuous intervals/sets?
Any help would be appreciated,
1 件のコメント
Image Analyst
2014 年 7 月 6 日
What's a continuous set? There is no continuous set of numbers in computers. If A is an array, then A has a certain, fixed and finite number of elements with certain definite values, so A must be discrete/digitized, not continuous.
採用された回答
Image Analyst
2014 年 7 月 6 日
Try this:
A = 0:360;
B = 0 : 60;
C = 45 : 60;
D = 270 : 360;
foundIndexesB = find(ismember(B, A))
foundIndexesC = find(ismember(C, A))
foundIndexesD = find(ismember(D, A))
allFoundIndexes = [foundIndexesB, foundIndexesC, foundIndexesD]
% Get rid of those numbers from A
A(allFoundIndexes) = [];
Note, it only works for integers. Why? See the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
2 件のコメント
その他の回答 (1 件)
Roger Stafford
2014 年 7 月 6 日
You might consult these sites:
http://www.mathworks.com/matlabcentral/fileexchange/31753-range-intersection
http://www.mathworks.com/matlabcentral/fileexchange/24254-interval-merging
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!