フィルターのクリア

can i compare two cell array with double and string value?

8 ビュー (過去 30 日間)
fatemeh
fatemeh 2013 年 12 月 22 日
回答済み: Walter Roberson 2013 年 12 月 24 日
i have a 303*14 dataset i want compare every raw of this dataset with a 1*14 vector
this dataset has double and string values but the vector just has string values in fact i want compare string values with double values!
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 22 日
How to compare double with string? Can you provide a short example: a 3x4 cell array fo example.
dpb
dpb 2013 年 12 月 22 日
編集済み: dpb 2013 年 12 月 22 日
Sotoo
>> c={'abc';2;'xyz'}; % some trivial data set
>> ismember({c{cellfun(@ischar,c)}}','xyz')
ans =
0
1
>>
maybe? Salt to suit for vectors, of course...
Now how to compare the doubles to strings -- for what definition of compare? If the strings are numeric representations then simplest would be to convert to numeric value w/ str2dble or the like and then do the comparison. Or, go the t'other way 'round and convert the doubles to character representation with appropriate number of significant digits and do the comparison in that domain.
Either way, as Azzi points out you'll need to define what it is you actually mean first...

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

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 12 月 24 日
row_is_the_same = arrayfun( @(rownum) isequal( YourDataset(rownum,:), TheVectorToCompareTo), 1:size(YourDataset,1));
The answer will be false for every row since a number is not the same as a string, but you didn't ask us for advice about dealing with that.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by