Live script plots not showing or overwriting
55 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Adrián Cotobal Gómez
am 23 Apr. 2023
Kommentiert: Dyuman Joshi
am 2 Dez. 2023
I am trying to plot 2 separate figures in the livescript, however it seems they are overwritting themselves and it only shows the second one.
If I put a break point right before the second plot, both appear in the code and the first one does not dissapear, what can I do?
here it is the code from the live script (file attached as well):
%1.figure 1
clc;clear all;close all;
f = @(x) 2*cosh(x/4)-x;
a=0;
b=6;
tol=10e-6;
x = linspace(0,10,1000);
figure(1)
plot(x, f(x));
hold on
line([0 10], [0 0])
hold off
%2.figure 2
clc; clear all; close all;
f = @(x) 2.*cosh(x/3)-x;
df= @(x) (-0.5).*sinh(x/4)-1;
x = linspace(0,10,1000);
figure(2)
plot(x, f(x));
hold on
line([0 10], [0 0])
hold off
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 23 Apr. 2023
Bearbeitet: Dyuman Joshi
am 23 Apr. 2023
clc; clear all; close all;
This is the root of your problem, this line clears all the data, variables, plots etc (basically any item in the workspace) and closes any figure you have generated before. Remove it and you should be good to go.
In general practice, I don't think there is any need to use this line in a script or a function. Read more about it here
4 Kommentare
Adithya
am 2 Dez. 2023
I'm having the same problem, and nothing going with clc/clear/close, as I don't use those at the beginning of scripts.
So far closing and reopening has not worked. VERY frustrating.
Dyuman Joshi
am 2 Dez. 2023
@Adithya, is your problem the same as OP's i.e. plots not showing in Live script?
Also, please post your whole code, so I can reproduce the behaviour and provide any suggestion/solution.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects 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!