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
0 件のコメント
採用された回答
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)
0 件のコメント
その他の回答 (1 件)
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');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!