How to Find a Value From Another Value?

I have a matrix, so I would like to find a value from the first column by using values from the last columns. For example, I have an specific value from the last column which I found by suing "find". How can I then find the value from the first column from that specific row by using the last column value?

 採用された回答

Birdman
Birdman 2017 年 12 月 7 日

0 投票

One approach:
A=[1 2 3;4 5 6;7 8 9];
[r,c]=find(A==9);
value=A(r,1)

3 件のコメント

Rafael
Rafael 2017 年 12 月 7 日
Your code works, but only the last line I just had to use.
Birdman
Birdman 2017 年 12 月 7 日
What did you want ?
Rafael
Rafael 2017 年 12 月 7 日
I got it working. I only had to use your last line code. I had it like this, Value=find(A(r,1))

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2017 年 12 月 7 日
編集済み: Andrei Bobrov 2017 年 12 月 7 日

0 投票

A = reshape(1:16,4,[]); % Let A - your array (example)
out = A(A(:,end) == 14,1)

2 件のコメント

Rafael
Rafael 2017 年 12 月 7 日
Can you explain to me what exactly does these codes do? I mean, 1:16 I understand, but the other things I don't.
Andrei Bobrov
Andrei Bobrov 2017 年 12 月 7 日
A = reshape(1:16,4,[]);
It's example of your array.

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

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

質問済み:

2017 年 12 月 7 日

コメント済み:

2017 年 12 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by