在单元格中搜索字符串并返回索引号 [英] Searching cell for string and return index number
本文介绍了在单元格中搜索字符串并返回索引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个20 x 2的单元格.两列均包含字符串.我想做的是在第二列中搜索一个字符串,并且第二列中的值与我的搜索字符串匹配,以返回第一列中的值.请参见下面的示例-我相信它将使事情变得更清楚.
I have a 20 x 2 cell. Both columns contains strings. What I would like to do is search for a string in column two and where the value in column 2 matches my search string to return the value in column 1. Please see my example below - I believe it will make things clearer.
name region
ABC USA
ASD EU
PLKDD EU
ERT EU
LKK ASIA
MNN USA
WER EU
基于搜索字符串"EU",我想要的结果如下
The result I would like based on the search string being "EU" is below
result
ASD
PLKDD
ERT
WER
推荐答案
您可以尝试 ismember
:
You can try ismember
:
x =
'ABC' 'USA'
'ASD' 'EU'
'PLKDD' 'EU'
'ERT' 'EU'
'LKK' 'ASIA'
'MNN' 'USA'
'WER' 'EU'
y = x(find(ismember(x(:,2), 'EU')),1)
y =
'ASD'
'PLKDD'
'ERT'
'WER'
这篇关于在单元格中搜索字符串并返回索引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文