Problem with saving the Data of programmaticaly created uitable

I create a variable size uitable programmaticly (not using GUIDE) which works well. What I am struggling with is saving the content of the created table, it keeps telling "Reference to non-existent field 'load_table'". Even if I try to save it in another callback it keeps telling the same error. Any ideas? much appreciated.

3 Comments

Without seeing the code it is impossible to guess, where the error is. So please edit your question and insert the relevant part of the code and a copy of the complete error message.
I have already attached a snapshot of the code. However here is the code:
% --- Executes on selection change in Act_Menu.
function Act_Menu_Callback(hObject, eventdata, handles)
Actuators = cellstr(get(hObject,'String')); %returns popupmenu3 contents as cell array
Actuator_selected = Actuators{get(hObject,'Value')}; %returns selected item from popupmenu3
Dynamic_states = evalin('base','Dynamic_states');
switch Actuator_selected
case 'Actuator 1'
moves = [1:Dynamic_states(1),]'
loads = zeros(size(moves))
tabledata =[moves loads]
columnname = {'Move', 'Load Mass'};
columnformat = {'char', 'short'};
columneditable = [false true];
load_table = uitable('Units','pixels','Position',[50 270 152 100],'ColumnWidth','auto','Data', tabledata,'ColumnName', columnname,'ColumnFormat', columnformat,'ColumnEditable', columneditable,'RowName',[] ,'BackgroundColor',[.7 .9 .8],'ForegroundColor',[0 0 0]);
case 'Actuator 2'
moves = [1:Dynamic_states(2),]'
loads = zeros(size(moves))
tabledata =[moves loads]
columnname = {'Move', 'Load Mass'};
columnformat = {'char', 'short'};
columneditable = [false true];
load_table = uitable('Units','pixels','Position',[50 270 152 100],'ColumnWidth','auto','Data', tabledata,'ColumnName', columnname,'ColumnFormat', columnformat,'ColumnEditable', columneditable,'RowName',[] ,'BackgroundColor',[.7 .9 .8],'ForegroundColor',[0 0 0]);
case 'Actuator 3'
moves = [1:Dynamic_states(3),]'
loads = zeros(size(moves))
tabledata =[moves loads]
columnname = {'Move', 'Load Mass'};
columnformat = {'char', 'short'};
columneditable = [false true];
load_table = uitable('Units','pixels','Position',[50 270 152 100],'ColumnWidth','auto','Data', tabledata,'ColumnName', columnname,'ColumnFormat', columnformat,'ColumnEditable', columneditable,'RowName',[] ,'BackgroundColor',[.7 .9 .8],'ForegroundColor',[0 0 0]);
end
And the error message is:
Reference to non-existent field 'load_table'.
Error in EnergyTool_GUI>Act_Menu_Callback (line 2518)
val_Load_Table = get(handles.load_table,'Data');
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in EnergyTool_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)EnergyTool_GUI('Act_Menu_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback

Sign in to comment.

Answers (1)

You use handles.load_table but you never created that. You created load_table without storing it in handles

3 Comments

I stored it in handles as shown below but still telling the same error ('table_handles' is non-existent field)
table_handles = guihandles(load_table);
guidata(load_table,table_handles);
val_Load_Table = get(handles.table_handles,'Data');
handles.mydata.Load_Table_val=val_Load_Table;
guihandles(load_table) looks through the figure that contains the load_table graphics object and finds all graphics objects with non-empty Tag where the Tag is a legal variable name, and creates a structure with one field for each of those tags.
When you then guidata() that structure, it effectively becomes (or replaces) the handles structure for all later calls.
If, in a later routine, you then try to access handles.table_handles that field would only exist if there had been a graphics object with Tag 'table_handles'
The uitable() that you are creating have no Tag, so even if they were created before the guihandles() call then they would not be recorded in the structure.
What you probably want is that once your handles structure has been created, and you have assigned table_handles the appropriate uitable() value,
handles.table_handles = table_handles;
guidata(hObject, handles);
This code works:
handles.Load_Data = uitable('Units','pixels','Data', tabledata,.....);
And then in the save button callback
val_Load_Table = get(handles.Load_Data,'Data');
handles.mydata.Load_Table_val = val_Load_Table;
Thanks everybody for your suggestions :)

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 15 Jan 2016

Edited:

on 19 Jan 2016

Community Treasure Hunt

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

Start Hunting!