how to get the coinciding value of a particular row and column
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
KSSV
on 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)
0 Comments
More Answers (1)
Andrei Bobrov
on 4 Oct 2017
Edited: Andrei Bobrov
on 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');
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!