[英]Matlab: in a matrix A, how to find the values of the fourth line, corresponding to some values on the first line?
17 2 4 14 14 16
19 6 20 9 1 15
A = 3 11 20 19 17 8
19 20 10 16 19 14
13 20 17 20 14 4
如何找到與第一行的2和14對應的第四行的值?
預期的結果: [20 16 19]
首先,您需要在第一行中找到等於2
或14
的條目
>> eqTo = [2;14];
>> sel = any( bsxfun( @eq, A(1,:), eqTo ), 1 )
0 1 0 1 1 0
現在,您使用邏輯索引從第四行提取相應的條目
>> A( 4, sel )
20 16 19
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.