# Iterate through matrix until no more possible calculations.

1 Ansicht (letzte 30 Tage)
DuckDuck am 19 Nov. 2014
Beantwortet: Thorsten am 19 Nov. 2014
I have an array that shortens up every time i do an iteration. But how do i know when there are no more possible calculations to be done and the size of the array cannot be shortened up any more. i'm thinking using while loop but don't know how to check it. Any help please.
Suppose i have a matrix
a=[1,2;
1,3;
1,4;
2,12;
2,15;
5,7;
5,8;
6,98;
6,99;
7,8;
7,9;
7,11;
9,14;
9,16;
12,18;
14,20;
20,35;
98,102;
99,204;
204,300;
301,305;
308,400];
every time i do an iteration i remove the elements of one of the arrays below. first
b=[1,2,3,4,12,15,18],
then
c=[5,7,8,9,14,16,20,35],
then
d=[6,98,99,102,204,300] and i'm left with
a=[301,305;308,400].
So how do i know there are no more iterations to go?
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Thorsten am 19 Nov. 2014
Store the b, c, d arrays as cell elements in cell b. Then insert the i'th row of a into anew if its not element of any list in b.
anew = [];
for i = 2:size(a, 1)
bi = 1;
while bi <= numel(b) && isempty(intersect(a(i,:), b{bi}))
bi = bi + 1;
end
if bi > numel(b) % a(i,:) not member of any b{bi}
anew(end+1,:) = a(i,:);
end
end
disp('anew')
disp(anew)
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on General Applications in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by