0
我有一個矩陣A(97x13)的特定值範圍從0到90查找一個特定行
我想在哪些值是低於45。
find(A(:,[4,7,10])<45);
特定行找我的問題是,我不知道如何將結果索引與整個A矩陣關聯起來。
有人可以幫我嗎?
我有一個矩陣A(97x13)的特定值範圍從0到90查找一個特定行
我想在哪些值是低於45。
find(A(:,[4,7,10])<45);
特定行找我的問題是,我不知道如何將結果索引與整個A矩陣關聯起來。
有人可以幫我嗎?
結果採用linear index的形式。你可以轉換到行和使用ind2sub
柱:
cols = [4,7,10];
ind = find(A(:,cols)<45);
[r, c] = ind2sub([size(A,1) numel(rows)], ind);
c = cols(c); %// change from "1,2,3" to "4,7,10"
爲了節省運行時間,你可以使用ind2sub
「手動」 版本:
cols = [4,7,10];
ind = find(A(:,cols)<45);
r = mod(ind-1,size(A,1))+1;
c = cols(ceil(ind/size(A,1)));
例子:
A =
8 66 87 57 4 24 10 82 3 55
24 44 50 62 80 31 59 81 67 56
73 53 47 36 83 62 45 31 46 78
3 22 21 34 72 13 71 63 44 73
84 42 45 89 9 65 65 18 82 52
給出
r =
3
4
1
c =
4 4 7
使用ind2sub獲得的行和列,例如:
>> A=round(rand(5,3)*90)
A =
85 19 18
79 27 20
50 42 15
56 21 20
53 76 39
>> [I,J] = ind2sub(size(A), find(A(:,[1,3])<45))
I =
1
2
3
4
5
J =
2
2
2
2
2
>>