comparing columns of cell arrays

2 ビュー (過去 30 日間)
Bouchra
Bouchra 2019 年 2 月 8 日
回答済み: Bouchra 2019 年 2 月 8 日
Hi,
I am new to matlab and would like to compare two cell arrays of a structure which have a different size.
My first field (drug.compound) of the structure (named drug) contains one column of IDs (28722x1) and my second field(drug.enzymes) contains one column of IDs 877x1. I would like to make a table in which the relation is shown between the IDs [28772×857] by a logical array.
Any suggestions?
I tried the strcmp function and == operator but not seem to work
  2 件のコメント
Stephen23
Stephen23 2019 年 2 月 8 日
編集済み: Stephen23 2019 年 2 月 8 日
@Bouchra Ezzamouri: please describe the contents of the cell arrays: are they numeric arrays, or character vectors, or string arrays, or ... ? If you are not sure, please run these commands:
class(drug.compound{1})
class(drug.enzymes{1})
and tell us their outputs. It would be easiest if you simply uploaded the structure in a .mat file, by clicking the paperclip button.
Bouchra
Bouchra 2019 年 2 月 8 日
the output is character vectors

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

採用された回答

Stephen23
Stephen23 2019 年 2 月 8 日
編集済み: Stephen23 2019 年 2 月 8 日
As most of the data seem to be numeric encoded as character vectors, then we can easily convert them from char to numeric arrays and use an efficient logical comparison:
>> Nc = str2double(drugb.compounds(:));
>> Ne = str2double(drugb.enzymes(:)).';
>> X = bsxfun(@eq,Nc,Ne);
>> size(X)
ans =
28772 1745
Some of the character vectors contain things like
"# Tanaka T, Tachibana H, Nonaka G, Nishioka I, Hsu FL, Kohda H, Tanaka O: Tannins and related compounds. CXXII. New dimeric, trimeric and tetrameric ellagitannins, lambertianins A-D, from Rubus lambertianus Seringe. Chem Pharm Bull (Tokyo). 1993 Jul;41(7):1214-20. ""Pubmed"":http://www.ncbi.nlm.nih.gov/pubmed/8374992 [Isolation]"
which will be converted to NaN and will therefore return false from the logical comparison.

その他の回答 (1 件)

Bouchra
Bouchra 2019 年 2 月 8 日
thankyou! this helped a lot

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by