how to display an output on a plot itself?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohiedin Bagheri
am 17 Jan. 2023
Kommentiert: Sam Chak
am 17 Jan. 2023
Hi friends,
for this code:
x = linspace(-5,2);
y = -x-3;
z = 2*x
figure(1)
plot(x, y)
hold on
plot(x, z)
legend('x','y','location','best')
ix = interp1(y-z,x,0)
How can I cahnge this code and what coding line I should add so the solution (intersection point of y and z function, i.e., ix = -1) be displayed on the plot itself in a box?
Thank you
0 Kommentare
Akzeptierte Antwort
Sam Chak
am 17 Jan. 2023
Bearbeitet: Sam Chak
am 17 Jan. 2023
Do you want to plot something like this?
x = linspace(-5, 2, 701);
y = - x - 3;
z = 2*x;
figure(1)
plot(x, y)
hold on
plot(x, z)
ix = interp1(y-z, x, 0);
iy = 2*ix;
plot(ix, iy, 'o', 'markersize', 15, 'linewidth', 3)
xlabel('x'), grid on
legend('y', 'z', 'location', 'best')
txt = ['\leftarrow intersection: x = ' num2str(ix)];
text(-1+0.25, -2, txt)
4 Kommentare
Sam Chak
am 17 Jan. 2023
@Mohiedin Bagheri, Don't mention it. Who knows I'll need your help in future.
Siehe auch
Kategorien
Mehr zu Function Creation 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!