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

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?

 채택된 답변

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

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.
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Timetables에 대해 자세히 알아보기

제품

릴리스

R2017a

질문:

2018년 7월 25일

댓글:

2018년 7월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by