MATLAB: How to create a UITABLE in GUI using a data from matlab variable workspace

callbackguimatlab guiuitable

Hi,
I'm still a beginner in MATLAB so hope this vast community can help me figure out how to solve my problem.
I'm creating a UITABLE using MATLAB GUI, and i want the UITABLE data to be the data from a variable named Table from the variable workspace. I totally confused in which callback function that i need to put my code on??
tq in advance for helping me

Best Answer

Nik - you could put this code in either the _CreateFcn for the uitable, or the _OpeningFcn of your GUI. If the former, then the code would be something like
function uitable1_CreateFcn(hObject, eventdata, handles)
% check to see if the variable exists in the base workspace
if evalin('base','exist(''Table'',''var'')')
% get the variable from the base workspace and save it to the table
data = evalin('base','Table');
set(hObject,'Data',data);
end
The above code would be near-identical for the _OpeningFcn - all you would have to do is replace hObject with handles.uitable1.
Note how the above code checks to see if the variable exists before trying to access it using evalin.
In the above example, Table was created in the workspace as
Table = randi(255,12,4);