# How can I extract the harmonic related numbers from a matrix?

1 view (last 30 days)
sia ben on 14 Jan 2020
Commented: sia ben on 15 Jan 2020
Hallo,
I have a array of numbers for example: (90 100 110 200 220 250 300 330 340 400 420 500)
I wand to make a function who find the harmonic related numbers with its index.
answer: (100 200 300 400 500) and ther index: (2 4 7 10 12). Theoreticaly it should find the second one aswell: (110 220 330) and index (3 5 8)
Thanks!

Akira Agata on 15 Jan 2020
x = [90 100 110 200 220 250 300 330 340 400 420 500];
tfUsed = false(size(x));
R = x./x';
idx = R == round(R);
pt = 1;
disp('--------------------------------')
while ~all(tfUsed)
disp(['Index : ',num2str(find(idx(pt,:)))])
disp('--------------------------------')
tfUsed(idx(pt,:)) = true;
pt = find(~tfUsed,1);
end
The result is as follows:
--------------------------------
Index : 1
--------------------------------
Answer: 100 200 300 400 500
Index : 2 4 7 10 12
--------------------------------
Index : 3 5 8
--------------------------------
Index : 6 12
--------------------------------
Index : 9
--------------------------------
Index : 11
--------------------------------

#### 1 Comment

sia ben on 15 Jan 2020
Thanks! That's it!