Effacer les filtres
Effacer les filtres

how to get the coinciding value of a particular row and column

1 vue (au cours des 30 derniers jours)
Elysi Cochin
Elysi Cochin le 4 Oct 2017
I have a table with values as below
tabl1 = {'A' 'B' 'C' 'D' 'E';
'F' 'G' 'H' 'I' 'J';
'K' 'L' 'M' 'N' 'O';
'P' 'Q' 'R' 'S' 'T';
'U' 'V' 'W' 'X' 'Y'};
Now if i give 2 letters, eg
var1 = 'U', and var2 = 'I',
i want to get the coinciding letter of 'U'th row and 'I'th column
that is letter "X"
var1 = 'A', and var2 = 'N',
i want to get the coinciding letter of 'A'th row and 'N'th column
that is letter "D"
how to do it in code

Réponse acceptée

KSSV
KSSV le 4 Oct 2017
clc; clear all ;
tabl1 = {'A' 'B' 'C' 'D' 'E';
'F' 'G' 'H' 'I' 'J';
'K' 'L' 'M' 'N' 'O';
'P' 'Q' 'R' 'S' 'T';
'U' 'V' 'W' 'X' 'Y'};
var1 = 'U' ;
var2 = 'I' ;
[r1,c1,v] = find(ismember(tabl1,var1)) ;
[r2,c2,v] = find(ismember(tabl1,var2)) ;
tabl1(r1,c2)

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 4 Oct 2017
Modifié(e) : Andrei Bobrov le 4 Oct 2017
[U,I] = find(ismember(tabl1,{'U','I'}))
out = tabl1(U(1),I(2))
or
fun0 = @(M,v1,v2)M(any(ismember(M,v1),2),any(ismember(M,v2)));
out = fun0(tabl1,'U','I');

Catégories

En savoir plus sur Tables 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