Error using figure First argument must be a figure object or a positive Integer

24 次查看(过去 30 天)
Hi, I keep getting the error message "Error using figure, First argument must be a figure object or a positive Integer". I'm trying to plot vertical acceleration of a projectile with no drag, which should be easy but I keep getting the same error message. The issue seems rather simple but has been frustrating me. Here is all related code to the error that I'm having
v0 = 50; %initial speed(m/s)
theta = 25; %launch angle (degrees)
N = 250; % Number of timesteps
a = zeros(1,N);
a(1) = -9.8;
a(2) = -9.8;
Tmax = 2*v0*sind(theta)/g; %values created elsewhere in code, no issue
t = linspace(0,2.5*Tmax,N); % seconds: Time axis,
for n = 3:N
a(n) = -9.8;
end
figure 4
plot(t,a)

回答(1 个)

Peter O
Peter O 2020-6-3
Figure is a function. Try:
figure(4)
This should activate a figure with ID number 4.
  2 个评论
Steven Lord
Steven Lord 2020-6-3
Note that figure(4) is not the same as figure 4. That is actually equivalent to figure('4') which passes a character into figure. While figure can accept some char vector inputs (pairs of parameter names and parameter values) it can't accept the char vector '4'.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by