Figure() Function doesn't work

Exactly as the title says. I cannot find anyone else with this issue so any help would be much appreciated. Here are some snippets of my code:
f = @(x) 1/sqrt(2*pi).*exp(-1/2.*(x.^2));
df = @(x) 1/sqrt(2*pi).*exp(-1/2.*(x.^2)) .* -x;
f_l = @(x,c) df(c).*(x-c) + f(c);
x_var = linspace(0,2.2,100);
actual_y = f(x_var);
linear_y = f_l(x_var,1);
figure(1)
plot(x_var , actual_y , x_var , linear_y)
xlim([0 2.2])
yline(0)
This code never produces a figure 1. It has managed to produce figure 3, figure 4, figure 6, and plenty of figure 11's all without the code you are looking at changing. The only thing that could be changed between those events is that clear all, close all, close all hidden or various other commands were tried. Putting figure(#) in my command window does nothing. i have tried to use figure(2) and figure(3) later in the code but they are equally useless. It really just feels like the figure() function doesn't work on my MATLAB. As far as I can remember, this has never worked for me either. Please let me know if I am doing anything wrong, but I cannot find any solution to this.

댓글 수: 8

Hi Christo,
what do you get when you type
which figure -all
Christo
Christo 2024년 3월 1일
built-in (C:\Program Files\MATLAB\R2023a\toolbox\matlab\graphics\figure)
David Goodmanson
David Goodmanson 2024년 3월 1일
편집: David Goodmanson 2024년 3월 1일
Does Matlab ever procuce a figure 1 that is blank, or is there no figure 1 window at all? And, lower down the the code is there ever a command that says just 'figure' with no figure number?
Christo
Christo 2024년 3월 1일
No, there are no mentions of figure() at all in the code. The code begins with clc; clear all, close all so there shouldn't be any open figures. The code does not produce Figure 1 unless I command "close all" and then immediately after put "figure()" or "figure(1)" into the command window. If i run the code in between I can no longer access Figure 1. No other figure(#) will work regardless of what I do, nothing will happen if I command figure(2), even if I can command Figure 1. However, when I run my code it seems to love assigning figure #12 to everything.
Just genuinely confused. Like I said too, as long as I have been using MATLAB on this laptop, I've never had figure() work correctly. I have had it work correctly on other desktops before.
Walter Roberson
Walter Roberson 2024년 3월 1일
Are you possibly using LiveScript ?
Christo
Christo 2024년 3월 1일
I am using LiveScript
Christo
Christo 2024년 3월 3일
Thanks! Seems like transferring to a .m would be the best option. I guess .mlx doesn't like mixing the figure() function with the ability to edit your plot.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2023a

태그

질문:

2024년 3월 1일

댓글:

2024년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by