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

15 ビュー (過去 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 Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by