필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Elysi Cochin
Elysi Cochin 2017년 10월 4일
편집: Andrei Bobrov 2017년 10월 4일
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