haibaraxx的个人博客分享 http://blog.sciencenet.cn/u/haibaraxx

博文

Matlab: 查找多个元素在矩阵中的位置

已有 19678 次阅读 2016-8-16 22:58 |个人分类:Matlab|系统分类:科研笔记

A=[1,2,3,4,5,7,1];

B=[1,3,5,6];

Determine which elements of B are also in A as well as their corresponding locations in A.


Syntax: [yn,pos]=ismember(B,A);


Output: yn=[1,1,1,0] % if an element of B is found in A, then yn returns 1 (ture), elsewhere, it returns 0 (false).

            pos=[1,3,5,0] % find the lowest index of locations. The lowest position index to B(1) is A(1).

     



https://blog.sciencenet.cn/blog-3031432-996864.html

上一篇:Matlab: find the position of NaN
下一篇:Matlab: concatenate two strings
收藏 IP: 134.1.1.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-9-27 12:00

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部