![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175020/image.png)
find value corresponding X value to a particular Y value
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sri satya ravi
am 11 Sep. 2016
Kommentiert: sri satya ravi
am 12 Sep. 2016
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 12 Sep. 2016
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!