フィルターのクリア

intersection between a dataset and a cell array

3 ビュー (過去 30 日間)
Doriana
Doriana 2018 年 10 月 1 日
編集済み: jonas 2018 年 10 月 1 日

Hi all, I have a dataset abc (6x1)and a cell array xyz(4x1). I want to find the common observations. Dataset abc:

'ObsNames' y
'obs1'    0
'obs2'    0
'obs3'    0
'obs4'    0
'obs5'    0
'obs6'    1

cell array: 4×1 cell array

    'obs2'
    'obs3'
    'obs4'
    'obs6'

I want to get a dataset that contains only the lines present in xyz array.

    'ObsNames' y
    'obs2'    0
    'obs3'    0
    'obs4'    0
    'obs6'    1

thank you

  1 件のコメント
jonas
jonas 2018 年 10 月 1 日
Can you upload a .mat file with your variables?

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

採用された回答

jonas
jonas 2018 年 10 月 1 日
編集済み: jonas 2018 年 10 月 1 日
Okay, I've never worked with datasets but they are quite similar to tables.
%%Load data
d1=load('xyz.mat');
d2=load('abc.mat');
%%Extract cell array with xyz names
xyzNames=d1.ObsNames_ds_ACP_selected_vars
%%Extract cell array with abc names and values
abc=d2.ds_ACP_selected_vars
abcNames=abs.Properties.ObsNames
abcValues=abc.Classvar;
%%Compare
[~,b]=intersect(abcNames,xyzNames)
%%Names
abcNames(b)
ans =
4×1 cell array
{'CCImpOpA' }
{'ProdottiAccesiMens'}
{'ProdottiInEssere' }
{'classe_eta' }
%%corresponding values
abcValues(b)
ans =
0
0
0
1

その他の回答 (0 件)

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by