Is there the possibility to discretize data comparing them with a function?

1 vue (au cours des 30 derniers jours)
Hello everyone, I am creating a matrix with 2 rows and several columns. I would like to compare the pairs of values of this matrix with another matrix that contains other pairs of numbers. The pairs of the second matrix derive them from a function.
The code is: Fr_2=0:0.01:5; r_theoric=zeros(1,length(Fr_2)); for i=1:length(Fr_2) r_theoric(i)=sqrt(27*((Fr_2(i)^2)/((2+Fr_2(i)^2)^3))); end R=[r_theoric;Fr_2]
The resulting curve has 3 "zones" (left, below the curve, right of the curve)
Basically, I would like the first couple to be discretized and I would like Matlab to tell me if these are on the left, below or to the right of the curve. Then.. How can I compare the pairs of the first matrix with the R matrix?

Réponse acceptée

Star Strider
Star Strider le 25 Juil 2018
Without your second matrix, it is necessary to create data to test code.
It is necessary to ‘close’ the polygon created by the curve so that the inpolygon function will work. I make no guarantees that this will work with your matrix, so you will have to experiment with that.
This works with my test data:
Fr_2=0:0.01:5;
r_theoric=zeros(1,length(Fr_2));
for i=1:length(Fr_2)
r_theoric(i)=sqrt(27*((Fr_2(i)^2)/((2+Fr_2(i)^2)^3)));
end
R=[r_theoric;Fr_2];
R(:,end+1) = [R(1,1); R(2,end)]; % <— Necessary To Complete The Polygon
[Rmax,idx] = max(R,[],2);
another_matrix = bsxfun(@times, rand(50, 2), [5 1]); % Create Data
Below = inpolygon(another_matrix(:,1), another_matrix(:,2), R(2,:), R(1,:)); % Logical Vector
Left = (another_matrix(:,1) < R(2,idx(1))) & ~Below; % Logical Vector
Right = ~Below & ~Left; % Logical Vector
figure
plot(R(2,:), R(1,:))
hold on
plot(another_matrix(Below,1), another_matrix(Below,2), 'pb')
plot(another_matrix(Left,1), another_matrix(Left,2), 'pg')
plot(another_matrix(Right,1), another_matrix(Right,2), 'pm')
hold off
grid
The plot may not be required for your code. It demonstrates that the code works here.
  2 commentaires
Star Strider
Star Strider le 27 Juil 2018
Gianluca Borgna’s ‘Answer’ moved here:
It was exactly what i wanted. Thanks. Now i have to understand how to put my data instead of yours.
Star Strider
Star Strider le 27 Juil 2018
My pleasure.
If you attach your data, preferably as a text file, I can probably help you with that.
Also, if my Answer helps you solve your problem, please Accept it!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by