How to use find() to find the corresponding output (not index!) of an input value

6 ビュー (過去 30 日間)
Luki
Luki 2017 年 1 月 12 日
回答済み: Jyotish Robin 2017 年 1 月 16 日
I am given a table with 2 columns - one contains P_in, the other P_out:
P_in = table(:,1)
P_out = table(:,2)
I want MATLAB to find the corresponding values of P_out to a set of P_in. I.e. I have P_in2 which is a subset of P_in. I want MATLAB to return the corresponding output values. I tried:
P_in2 = find(table(P_in2,2));
I get an error: Subscript indices must either be real positive integers or logicals.
So apparently find() can only deal with integers. Also, I think, find() only returns indices. How can I solve this problem?

採用された回答

Jyotish Robin
Jyotish Robin 2017 年 1 月 16 日
Hi Luki,
You could try using the functions "arrayfun" and "find" together to resolve the issue.
The relevant indices can be found using the following command:
>>idxs = arrayfun(@(x)find(P_in==x,1),P_in2)
Now you can use these indices to index into P_out as follows:
>>ans = P_out(idxs);
Hope this helps!

その他の回答 (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