GUI + Reference to non-existent field 'axes1'.

1 visualizzazione (ultimi 30 giorni)
hi all.
I'm working on a project, where i load data ind by "importdata". I want to plot some funktion from these data.
I have created a funktion that open a direction and select a file from this.
this funkion is created like this:
function handles = RoboTrainer( handles )
[filename, pathname] = ...
uigetfile({'*dat'},'File Selector');
[Time,Position,Velocity,RoboForce,AppliedForce,Repetition] =... importfile(fullfile(pathname, filename));
%% GUI variables
handles.MyData.Time = Time;
handles.MyData.Position = Position;
handles.MyData.Velocity = Velocity;
handles.MyData.RoboForce = RoboForce;
handles.MyData.AppliedForce = AppliedForce;
handles.MyData.Repetition = Repetition;
end
I have another function that has to plot a funktion from Time and Position.
function handles = TimePosition( handles )
Sample = length( handles.MyData.Time );
tid=linspace(0,(Sample*0.05),Sample);
axes(handles.axes1);
plot(tid,handles.MyData.Position);
ylabel ('position'); xlabel ('tid/sek'); title ('Position');
end
In my GUI i have created a axes (named axes1).
function axes1_CreateFcn(hObject, eventdata, handles)
handles = RoboTrainer( handles );
guidata(hObject, handles);
handles = TimePosition( handles );
guidata(hObject, handles);
but when i run my GUI, i got this error: "Reference to non-existent field 'axes1'." i don know what I make wrongly?
is there anyone to help me please?
i did not know how to explain the problem without explain all my code :(.

Risposta accettata

Geoff Hayes
Geoff Hayes il 31 Ott 2014
Mehdi - put a breakpoint at the first line of your axes1_CreateFcn function, then re-run your GUI. When the debugger pauses at this line, look at handles structure - it is probably an empty object and so the error message makes sense (I reproduced this with a simple GUI).
If you want to populate your axes in this manner (calling the RoboTrainer and TimePosition functions), I would just put this code in the OpeningFcn of your GUI when the handles structure has all of its widget/control (i.e. axes1) fields defined. Something like
function MyGui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles = RoboTrainer(handles);
handles = TimePosition(handles);
guidata(hObject, handles);
Try the above and see what happens!
  2 Commenti
mehdi
mehdi il 31 Ott 2014
thank you very much sir.
it works now! :)
I always thought that i call funktions in my axes_callback.
I have forgotten about OpeningFcn function.
Geoff Hayes
Geoff Hayes il 31 Ott 2014
Glad that it works!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Language Fundamentals in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by