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

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by