フィルターのクリア

Comparing Couple of Cell Array String

1 回表示 (過去 30 日間)
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 6 月 30 日
コメント済み: Angga Lisdiyanto 2016 年 6 月 30 日
Hi, i want to compare a couple of cell array string. In example :
dataset = {
'i', 'love';
'love', 'you';
'you', 'so';
'so', 'much'
}
if i have below data test :
data_test = {'love', 'you'}
then i want to get below result (according dataset) :
'love' 'you'
Else if my data is like below :
data_test = {'love', 'much'}
Then i want to get below result (according dataset) :
'love' 'you'
So, the process is getting first word. Then getting squence of words in dataset that match with first word...
Is that possible?
Thanks in advance.

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 6 月 30 日
data = {
'i', 'love';
'love', 'you';
'you', 'so';
'so', 'much'
};
data_test = {'love', 'much'};
out = data(ismember(data(:,1),data_test(1)),:);
  1 件のコメント
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 6 月 30 日
Thanks, this is what i am looking for.
The result is correct as according dataset words' squence.

サインインしてコメントする。

その他の回答 (2 件)

KSSV
KSSV 2016 年 6 月 30 日

KSSV
KSSV 2016 年 6 月 30 日
clc; clear all
dataset = {
'i', 'love';
'love', 'you';
'you', 'so';
'so', 'much'
};
data_test = {'love', 'you'} ;
count = 0 ;
for i = 1:length(dataset)
for j = 1:length(data_test)
k = strcmp(dataset{i},data_test{j}) ;
if k
count = count+1 ;
iwant{count} = dataset{i};
end
end
end
iwant
  1 件のコメント
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 6 月 30 日
編集済み: Angga Lisdiyanto 2016 年 6 月 30 日
Hi, thanks for answering.
I have a problem, if my data_tes is :
data_test = {'love', 'so'}
then i am still got :
'love' 'so'
How to getting result 'love' 'you' ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by