'Error using axes' when I use functions in GUI

I want the plot to be in axes1 of my GUI, but instead, a new figure opnes. This is only the case when I use an own function inside the GUI. This is my Code: (without Inputs)
if true
% code
...
x = linspace(0,L,n); % Knotenvektor
[S, M] = systemmatrizes(x, E, I, mu);
bc = [1, 1, a; 1, 2, b; n, 3, 0; n, 4, 2];
[Me, Se, r] = linearsystem(x, M, S, q, bc, m);
y = Se\r;
wa = y(1:2:2*n);
axes(handles.axes1);
plot(x,wa)
axis([0 1.1*L -1 1],'square');
end
And this is the Error:
_Error using axes Invalid axes handle
Error in BalkenbiegungGUI>togglebutton1_Callback (line 266) axes(handles.axes1);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in BalkenbiegungGUI (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)BalkenbiegungGUI('togglebutton1_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating DestroyedObject Callback.__
Line 266 is axes(handles.axes1); If I don't use my functions systemmatrices and linearsystem, it works. But I need them. What am I doing wrong?

7 Comments

Hello,
where are the variables mu and m in the Callback Function defined? Better is sharing the whole Code and all functions that i can try.
plot( handles.axes1, x,wa )
would be a far better way of making sure you plot on the axes you want, though that will not solve the error you have as in your case it appears that handles.axes1 is no longer an axes.
What do you get on command line if you put a breakpoint in and type
handles.axes1
before that line? And what do you get if you do the same before the call to systemmatrizes?
Hello, thank you for the answers. I will keep trying
if true
% code
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton1)
% Eingabeparameter aus der GUI
L = str2double(get(handles.laenge,'string'));
n = str2double(get(handles.knoten,'string'));
E = str2double(get(handles.emodul,'string'));
I = str2double(get(handles.flaechentraegheitsmoment,'string'));
mu = str2double(get(handles.massendichte,'string'));
nT = str2double(get(handles.zeitschritte,'string'));
m = get(handles.quadraturordnung, 'value');
x = linspace(0,L,n); % Knotenvektor
a=0;
b=0;
q=@(x)0;
[S, M] = systemmatrizes(x, E, I, mu);
bc = [1, 1, a; 1, 2, b; n, 3, 0; n, 4, 2];
[Me, Se, r] = linearsystem(x, M, S, q, bc, m);
y = Se\r;
wa = y(1:2:2*n);
axes(handles.axes1);
plot(x,wa)
axis([0 1.1*L -1 1],'square');
end
this is the entire code till now. its not finished, there comes a lot more, but I want to solve this problem before I go on. If i use plot(handles.axes1, x, wa) the error changes to "Error using plot Invalid handle."
So what do you get when you use breakpoints and type the things I asked on command line at the relevant points in the code?
I got "handle to deleted object". i never deleted anything in the .fig file. With a new axes2 it works now, but I got some new problems I can't even explain :D e.g. if i start the gui, 4(!) empty figures appear, then the plot appears in the GUI in axes2... I will try to solve this. Thank you for the answers
Unless you have done some really bad things in other functions of your GUI or have corrupted your .fig file you should never have a deleted axes in a GUIDE GUI (unless you deliberately delete it which would be a bizarre thing to do usually!).
Check you don't have things like
clear all
or other sledgehammer type functions in your GUI file.
I must admit I don't understand everything you said, but it works now, somehow I did it :D

Sign in to comment.

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Asked:

on 5 Apr 2018

Commented:

on 6 Apr 2018

Community Treasure Hunt

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

Start Hunting!