search content in table

2 vues (au cours des 30 derniers jours)
VISHNU DIVAKARAN PILLAI
VISHNU DIVAKARAN PILLAI le 10 Jan 2022
Modifié(e) : Campion Loong le 12 Jan 2022
i have a table name 'dcode'
d={':';'M';'D';'MD';'A';'AM';'AD';'AMD'};
d_address={'000';'001';'010';'011';'100';'101';'110';'111'};
dcode=table(d,d_address);
i would like access the equivalent value of 'D' in column 1 from column 2 .
( if i search the value for D i need to get ans as 010 from column 2)
can u please help me how to do it.
thanks in advance

Réponse acceptée

Geoff Hayes
Geoff Hayes le 11 Jan 2022
@VISHNU DIVAKARAN PILLAI - you could try something like
dcode.d_address(strcmp(dcode.d,'D'))
where we use strcmp to return a logical array of zeros and ones where a one will indicate a match (i.e. identical to 'D"). This logical array will then be used to determine the value of the second column whose first column value matches to 'D'.
  1 commentaire
VISHNU DIVAKARAN PILLAI
VISHNU DIVAKARAN PILLAI le 11 Jan 2022
thanks alot!!!

Connectez-vous pour commenter.

Plus de réponses (1)

Campion Loong
Campion Loong le 12 Jan 2022
Modifié(e) : Campion Loong le 12 Jan 2022
If you are always using the values of d as a 'key' to look up other table variables, I would use straightly use d as the table's RowNames:
d_address=string([0;1;10;11;100;101;110;111]);
d_address = pad(d_address,3,"left",'0')
d_address = 8×1 string array
"000" "001" "010" "011" "100" "101" "110" "111"
% note I replace ':' with '::' as ':' is a reserved subscripting character
d=["::";"M";"D";"MD";"A";"AM";"AD";"AMD"];
dcode=table(d_address,'RowNames', d');
dcode('D',:)
ans = table
d_address _________ D "010"

Community Treasure Hunt

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

Start Hunting!

Translated by