![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175020/image.png)
find value corresponding X value to a particular Y value
3 次查看(过去 30 天)
显示 更早的评论
a = 5;
n = 1:4;
theta_teta = -10;
delta_theta = 40;
theta = -10:1:30;
for j = 1: length (n);
for i = 1:length(theta)
f(i) = 1-exp(-a*((theta(i)-theta_teta)/delta_theta)^n(j));
end
plot (theta,f)
max_f = sum(f)
hold on
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156287/image.png)
Hi;
I have a plot which is shown in the image above. I want to find the x value corresponding to 0.5 and 0.9 of the maximum y values for the lines i.e. at 0.5 and 0.9 what is the respective x values for the different lines.
0 个评论
采纳的回答
Image Analyst
2016-9-12
Would interp1 be accurate enough for you? If so, try this:
a = 5;
n = 1:4;
theta_teta = -10;
delta_theta = 40;
theta = -10:1:30;
for j = 1: length (n);
for i = 1:length(theta)
f(i) = 1-exp(-a*((theta(i)-theta_teta)/delta_theta)^n(j));
end
plot (theta, f, 'LineWidth', 2);
max_f = sum(f);
fprintf('For n = %d, the sum of f (for some reason called max_f) = %f.\n', j, max_f);
grid on;
hold on;
% Find x value for y = 0.5
x50(j) = interp1(f, theta, 0.5);
line([x50(j), x50(j)], [0, 0.5], 'LineWidth', 2, 'Color', 'k');
fprintf('For n = %d, y = 0.5 at x = %f.\n', j, x50(j));
% Find x value for y = 0.9
x90(j) = interp1(f, theta, 0.9);
line([x90(j), x90(j)], [0, 0.9], 'LineWidth', 2, 'Color', 'k');
fprintf('For n = %d, y = 0.9 at x = %f.\n', j, x90(j));
end
legend('n=1', 'n=2', 'n=3', 'n=4', 'Location', 'east');
% Put lines across at y = 0.9 and 0.5
line(xlim, [0.5, 0.5], 'LineWidth', 2, 'Color', 'k');
line(xlim, [0.9, 0.9], 'LineWidth', 2, 'Color', 'k');
% Label the axes
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175020/image.png)
For n = 1, the sum of f (for some reason called max_f) = 32.540191.
For n = 1, y = 0.5 at x = -4.439359.
For n = 1, y = 0.9 at x = 8.435958.
For n = 2, the sum of f (for some reason called max_f) = 24.668279.
For n = 2, y = 0.5 at x = 4.894287.
For n = 2, y = 0.9 at x = 17.153014.
For n = 3, the sum of f (for some reason called max_f) = 19.624252.
For n = 3, y = 0.5 at x = 10.702175.
For n = 3, y = 0.9 at x = 20.896785.
For n = 4, the sum of f (for some reason called max_f) = 16.262926.
For n = 4, y = 0.5 at x = 14.406551.
For n = 4, y = 0.9 at x = 22.955276.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!