Intersection of a row and column from a matrix

6 ビュー (過去 30 日間)
Meera
Meera 2020 年 12 月 7 日
コメント済み: Ameer Hamza 2020 年 12 月 8 日
Hi,
I would like to know, how is it possible to find out the exact intersection of a row and a column from a matrix. It should only deliver one value as the answer (like manually reading the intersect of the row and column from a table).
Below is an analog to what I am doing. The matrix which I am working with is a 35x41 matrix.
As an example, by using the code below, if im searching for the intersect of x==1 and y==3, I will get P=[1;2] but I expact 2 as the answer. Is there any way to realisize this?
Thank you!
p=[1 2 3;4 1 2;2 8 1];
x=input('x?')
if x==1
x=p(:,1)
elseif x==2
x=p(:,2)
elseif x==3
x=p(:,3)
end
y=input('y?')
if y==1
y=p(1,:)
elseif y==2
y=p(2,:)
elseif y==3
y=p(3,:)
end
P=intersect(x,y)

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 7 日
Are you looking for this?
p=[1 2 3;4 1 2;2 8 1];
x = input('x? ');
y = input('x? ');
P = p(y,x)
  4 件のコメント
Meera
Meera 2020 年 12 月 8 日
Based on your answer, I have integrated it into my code and did some adjustments to it and it worked! Thank you very much for the help :D
Ameer Hamza
Ameer Hamza 2020 年 12 月 8 日
I am glad to be of help! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by