GUI calls function1 which has a uitable and callback...

2 Ansichten (letzte 30 Tage)
Justin Ruiz
Justin Ruiz am 9 Sep. 2019
Kommentiert: Adam Danz am 10 Sep. 2019
I now understand the uitable DeleteFcn doesn't have an output when running in a GUI environment. However, is it possible to define a handle in this subfunction callback to be used in the primary function - not the main GUI.
Here is the order. User presses button in GUI and executes function1. Within function1 I have...
uit = uitable(f,'Data',tabs,'Position',[10 100 700 200],'DeleteFcn',@MyDeleteFcn);
In the callback MyDeleteFcn
function MyDeleteFcn(t,event)
handles.data = get(t,'Data');
guidata(handles.data,handles);
end
Back in function1, I try and use after uiwait(f);
k = guidata(handles.data);
But it states that handles.data doesn't exist. Am I not defining something correct within MyDeleteFcn or is it not possible to use a subfunction variable outside of the GUI 'workspace'? I don't need to send any additional variables or info into MyDeleteFcn except the uitable data. I just need to somehow gather user table input for writing to a file further down in function1. I can clarify if needed! Any and all answers will be appreciated! Prior Context if needed.
  3 Kommentare
Adam Danz
Adam Danz am 10 Sep. 2019
Then follow Stephen's advice below.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 10 Sep. 2019
Bearbeitet: Stephen23 am 10 Sep. 2019
The guidata documentation states that its first input argument must be a handle to any graphics object in your GUI. What is its first input argument in your code?
guidata stores whatever the second argument is (commonly people use it for storing the so-called handles structure used in GUIDE) in the parent figure of the graphics object given as its first argument. Later you call it with just one input argument (again the handle of a graphics object in the same figure) and voila!, you get your data back. That is all.
You probably want something more like this:
function MyDeleteFcn(uit,event)
handles = guidata(uit); % get structure from figure
handles.data = get(uit,'Data');
guidata(uit, handles); % store structure in figure
end
Not that you will likely need to obtain the handles structure first, because guidata does not do any magical merging or combining or anything like that: when called with two arguments, it will simply overwrite the original data (if any) stored in that figure.
PS: if you are writing your own GUI (and sensibly avoiding GUIDE) then I recommend simply using nested function to pass data between functions in your GUI. They are simple, efficient, intuitive, and avoid the whole pointless indirection of guidata.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by