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

3 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Jyotish Robin
Jyotish Robin el 16 de En. de 2017
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!

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by