"polyxpoly" doesn't intersect lines correctly

조회 수: 7 (최근 30일)
Josh Wolstenholme
Josh Wolstenholme 2022년 7월 13일
답변: Ayush 2023년 9월 28일
I have some grain size data plotted in a semilogx plot and would like to find out the cumulative percentages for different abundance levels. To do this I have been using "polyxpoly" but the intesection points don't align where I'd expect
In terms of the code used to produce the intersects:
intersect_x = 0.0005:0.0005:0.255;
intersect_y(1:510) = 0.84;
for x = 1:height(wolman.s1_us)
date = datestr(wolman.s1_us.Time(x),'dd-mm-yyyy');
semilogx(grain_size,wolman.s1_us{x,:},"DisplayName",date,"LineWidth",lW);
hold on
[xi(x),yi(x)] = polyxpoly(grain_size,wolman.s1_us{x,:},intersect_x,intersect_y);
scatter(xi,yi,"DisplayName",date)
end
line3 = yline(0.84,'-',yLineLabels(3),"DisplayName",yLineLabels{3});
Any help on this would be greatly appeciated!

채택된 답변

Ayush
Ayush 2023년 9월 28일
Hey Josh,
I understand that you are facing an issue with finding the cumulative percentages for different abundance levels based on grain size data plotted in a “semilogx” plot. You have been using the "polyxpoly" function to find the intersection points, but they do not align as expected.
For reproducing the exact issue at my end, code is required.
Meanwhile, you can convert the data to linear scale before using “polyxpoly” and then convert the resulting intersection points back to the logarithmic scale as the “polyxpoly” function operates on linear coordinates and may not give accurate intersection points when used with logarithmic scales. Here’s an example of how you can modify your code:
intersect_x = 0.0005:0.0005:0.255;
intersect_y = 0.84 * ones(size(intersect_x));
for x = 1:height(wolman.s1_us)
date = datestr(wolman.s1_us.Time(x), 'dd-mm-yyyy');
semilogx(grain_size, wolman.s1_us{x, :}, 'DisplayName', date, 'LineWidth', lW);
hold on
% Convert to linear scale for intersection calculation
linear_grain_size = 10.^grain_size;
linear_data = 10.^wolman.s1_us{x, :};
% Calculate intersection points in linear scale
[linear_xi, linear_yi] = polyxpoly(linear_grain_size, linear_data, intersect_x, intersect_y);
% Convert intersection points back to logarithmic scale
xi = log10(linear_xi);
yi = log10(linear_yi);
scatter(xi, yi, 'DisplayName', date);
end
line3 = yline(0.84, '-', yLineLabels(3), 'DisplayName', yLineLabels{3});
For more information on “semilogx” plot and “polyxpoly”, refer to MathWorks documentation link below:
  1. https://in.mathworks.com/help/matlab/ref/semilogx.html
  2. https://in.mathworks.com/help/map/ref/polyxpoly.html
Hope this information helps!
Regards,
Ayush Goyal

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by