Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
roblocks
roblocks le 29 Juin 2016
Commenté : roblocks le 29 Juin 2016
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!

Réponse acceptée

Walter Roberson
Walter Roberson le 29 Juin 2016
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 commentaire
roblocks
roblocks le 29 Juin 2016
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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by