我有一個2 * 3 * 3的矩陣a
:使用發現沿第三維
a=[1 1 1;1 1 1];
a(:,:,2)=[1 1 1;1 1 1]+1;
a(:,:,3)=[1 1 1;1 1 1]+2;
認爲第三個維度的深度值。我想找到在該a
大於2。在這種情況下,結果應該是深度:
[3 3 3;3 3 3]
有沒有辦法做到在一個量化的方式?
我嘗試
我嘗試以下,但它不是做得比較工作:
inds=find(a>2) %find indices of elements>2
lev=ceil(inds/2/3) %divide by the size of each layer. it returns the layer indices on which the an element>2 is
depths = reshape(lev,2,3)
inds =
13
14
15
16
17
18
lev =
3
3
3
3
3
3
depths =
3 3 3
3 3 3
在這種情況下工作,但它是一個幸運的情況。
如果我使用:
a=[1 1 1;1 1 2];
a(:,:,2)=[1 1 1;1 1 2]+1;
a(:,:,3)=[1 1 1;1 1 2]+2;
現在不能因爲一起的最後一列工作,我有一個以上的值大於2.事實上:使用
inds=find(a>2) %find indices of elements>2
lev=ceil(inds/2/3) %divide by the size of each layer. it returns the layer indices on which the an element>2 is
depths = reshape(lev,2,3)
inds =
12
13
14
15
16
17
18
lev =
2
3
3
3
3
3
3
inds =
12
13
14
15
16
17
18
lev =
2
3
3
3
3
3
3
錯誤重塑 要RESHAPE元素的數量不能改變。
我看不到解決方法。
我也試着用'第一'選項使用find
,但根本沒有成功。
但是你希望深度中的所有元素大於2或至少有一個元素大於2? –
每個第三維列的第一個元素。如果我們使用(x,y,z)座標,我需要每個(x,y)對的第一個z – shamalaia
第二種情況下應該輸出什麼? – codeaviator