Logical Indexing Question

Hello everyone,
Lets say I have the following 2d matrices for plotting a surface:
th1 = 0:180;
th2 = 0:90
ph1 = 0:360;
ph2 = ph1;
[theta1 phi1] = meshgrid(th1,ph1);
[theta2 phi2] = meshgrid(th2,ph2);
rho1 and rho2 are values that correspond to th1/ph1 and th2/ph2, respectively.I'd like to compute error = rho2 - rho1 but this isn't possible directly since the matrices are different sizes. So, I'd like to compute "error" only for the values where theta1 and phi2 match up (i.e. union, in this case values of theta from 0 to 90). What is the best way to go about this? Can I use logical indexing somehow?

Réponses (2)

the cyclist
the cyclist le 4 Avr 2011

1 vote

Use the ISMEMBER command.
For example,
index_to_1_in_2 = ismember(th1,th2);
index_to_2_in_1 = ismember(th2,th1);
th1_to_use = th1(index_to_1_in_2);
th2_to_use = th2(index_to_2_in_1);
Matt Fig
Matt Fig le 4 Avr 2011

0 votes

Please go back and format your question using the {} Code button.
How can you form th2/ph2 when they are different sizes?

Community Treasure Hunt

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

Start Hunting!

Translated by