フィルターのクリア

Access Table rows if variable value == ... Problems with string variables.

2 ビュー (過去 30 日間)
roblocks
roblocks 2016 年 6 月 29 日
コメント済み: roblocks 2016 年 6 月 29 日
Dear All, suppose you have a table. I want to access certain rows based on variables values, for example if datecode == 20001231 & country_code == 'ES'. The following code works for numerical variables, but not for strings:
test = EBADATA_DEFINITIONS(EBADATA_DEFINITIONS.MATURITY_CODE == 999 ...
& EBADATA_DEFINITIONS.INFORMATION_CODE == 34010 ...
& strcmp(EBADATA_DEFINITIONS.C_COUNTRY_CODE,'ES'),:);
I have tried to manipulate the country column in various ways before running the command above , but I always end up with one or another error.
EBADATA_DEFINITIONS.C_COUNTRY_CODE = char(EBADATA_DEFINITIONS.C_COUNTRY_CODE)
EBADATA_DEFINITIONS.C_COUNTRY_CODE = cell2str(EBADATA_DEFINITIONS.C_COUNTRY_CODE)
Could someone point me towards the correct way of doing this?
I appreciate your help!
Best!

採用された回答

Walter Roberson
Walter Roberson 2016 年 6 月 29 日
It seems to work for me:
t = cell2table({15, 134, 'hello'; 82, 419, 'there'; 15, -999, 'hello'}, 'VariableNames', {'MATURITY_CODE', 'INFORMATION_CODE', 'C_COUNTRY_CODE'});
t(t.MATURITY_CODE == 15 & strcmp(t.C_COUNTRY_CODE, 'hello'),:)
  1 件のコメント
roblocks
roblocks 2016 年 6 月 29 日
it works for me now as well after not-charing it. I must have forgotten to unchar when I tested the code and then posted. Thanks Walter!

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

その他の回答 (0 件)

カテゴリ

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