MATLAB Answers

How can I fix "Undefined operator '-' for input arguments of type 'matlab.ui.Figure'"

2 views (last 30 days)
I am working on the function to plot some figures. However, when I run the program that call that funciton that error appears. How can I fix it?
This is the part of the function where the error appears:
si=figure-1; %% The error is here
for i=1:outputs
plot(Y(i,:),'bx'); hold on
plot(y2(i,:),'ro');hold off
if outputs==1,
title('Observations = x Network output=o')
title(['Observations = x Network output=o (output # ',num2str(i) ')'])


Sign in to comment.

Accepted Answer

Jon on 1 Sep 2020
Edited: Jon on 1 Sep 2020
figure is a MATLAB command that will open up a new figure.
MATLAB is telling you, it does not make any sense to subtract 1 from a function that is opening a new figure.
If you want to find out what the current figure number is so you can start numbering from there you could do something like
figNo = get(gcf,'Number')
where gcf means get current figure, and you are asking for its Number property

More Answers (1)

Steven Lord
Steven Lord on 1 Sep 2020
In releases prior to the introduction of the new graphics system in release R2014b, Handle Graphics functions like figure often returned a number representing a handle to a graphics object.
It was possible to perform arithmetic on those numbers, though there's no guarantee that the result of those arithmetic operations would return a handle to an object.
With the new graphics system figure returns a figure object and that figure object does not have the arithmetic operators defined on it.
Based on what you're trying to do (plot each results on a separate figure) you don't need to do arithmetic. Just call figure (no inputs, no outputs) to open a new figure for each set of results you want to plot.
x = 0:360;
for k = 1:4
axis([0 360 -1 1])
plot(x, sind(k*x))

Community Treasure Hunt

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

Start Hunting!