MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   八度/ Matlab:向量化'=='运算符? (https://www.labfans.com/bbs/showthread.php?t=26475)

poster 2019-12-14 20:13

八度/ Matlab:向量化'=='运算符?
 
我可以使用“ ==”运算符和“ find()”函数在矢量“数据”中查找值(即45)的位置:

data = [ 71 65 23 45 34 12 21 34 52 ]; value = 45; find (data == value) ans = 4 有没有办法在不使用循环的情况下对多个值执行相同的操作,即我想在一次调用中获得[4 5 7]:

values = [ 45 34 21 ]; find (data == values) error: mx_el_eq: nonconformant arguments (op1 is 1x9, op2 is 1x3) error: evaluating argument list element number 1 error: evaluating argument list element number 1

[B]回答:[/B]

尝试[URL="http://www.mathworks.com/help/techdoc/ref/ismember.html"]ismember[/URL]函数:

data = [ 71 65 23 45 34 12 21 34 52 ]; values = [ 45 34 21 ]; find(ismember(data, values)) 给予:

ans = 4 5 7 8

[url=https://stackoverflow.com/questions/5183457]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 02:58

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.