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

1 次查看(过去 30 天)
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

采纳的回答

KSSV
KSSV 2017-10-4
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)

更多回答(1 个)

Andrei Bobrov
Andrei Bobrov 2017-10-4
编辑:Andrei Bobrov 2017-10-4
[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');

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by