How to use find() to find the corresponding output (not index!) of an input value
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Luki
le 12 Jan 2017
Réponse apportée : Jyotish Robin
le 16 Jan 2017
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?
0 commentaires
Réponse acceptée
Jyotish Robin
le 16 Jan 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!
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!