필터 지우기
필터 지우기

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

조회 수: 17 (최근 30일)
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
figure(si+i);
subplot(211)
plot(Y(i,:),'bx'); hold on
plot(y2(i,:),'ro');hold off
if outputs==1,
title('Observations = x Network output=o')
else
title(['Observations = x Network output=o (output # ',num2str(i) ')'])
end
grid

채택된 답변

Jon
Jon 2020년 9월 1일
편집: Jon 2020년 9월 1일
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

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 9월 1일
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
figure
axis([0 360 -1 1])
plot(x, sind(k*x))
end

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by