MATLAB Answers

Error when uploading Cell Array to UI Table in GUI

1 view (last 30 days)
hamzah khan
hamzah khan on 15 Jun 2020
Commented: hamzah khan on 15 Jun 2020
I am making a GUI without the GUIDE, I have this data file, I cannot upload it into the table using a push button
This is the code. I am using for the table
f = figure('Visible','off','Units', 'centimeters', 'Position',[1.5,1.5,28,16.5]);
AddBody = uicontrol('Style','pushbutton','String','AddData','Units', 'centimeters','Position',[21.5,15,3,1],'Callback',{@AddBody_Callback});
AssemblyData= {0,0};
AssemblyTable= uitable(f, 'Units', 'centimeters','Position', [1,1,7,5], 'Data', AssemblyData,'ColumnEditable',[true, true], 'ColumnName',{'Name'; 'Size'},'CellEditCallback', {@AssemblyEdit_Callback});
AxesHandle = axes (f, 'Units', 'centimeters', 'Position',[1,7,20,9]);
function AddBody_Callback(source,eventdata)
[files,pathToFiles] = uigetfile('*.mat',...
'Select One or More Files', ...
'MultiSelect', 'on');
[BodyDataAdd,k,FileNames] = BodyDataLoad(files,pathToFiles);
if isempty(BodyData)
BodyData= BodyDataAdd;
BodyData= [BodyData; BodyDataAdd];
for TempIndex= 1:k
if k==1
AssemblyData{BodyNumber+TempIndex,1} = FileNames;
AssemblyData{BodyNumber+TempIndex,1} = FileNames;
%AssemblyData{TempIndex,2} = BodyDataAdd{TempIndex,1};
AssemblyData{BodyNumber+TempIndex,2} = BodyData{BodyNumber+TempIndex,1}{1,1};
BodyNumber= BodyNumber+k;
set(AssemblyTable, 'Data',AssemblyData);
Now the function, Body Data Load is as follows
function [Result,h, files] = BodyDataLoad(files,pathToFiles)
out = {};
OUT1 = {}
OUT2 = {}
OUT3 = {}
Result = {}
if ~iscell(files)
out{1} = load(fullfile(pathToFiles, files));
for k = 1:length(files)
out{k} = load(fullfile(pathToFiles, files{k}));
out = struct2cell(out{1});
h = size(out,1)
OUT1{1} = out{1}
OUT1{1} = full(OUT1{1})
OUT2{1} = out{2}
OUT2{1} = full(OUT2{1})
OUT3{1} = out{3}
OUT3{1} = full(OUT3{1})
Result = {OUT1; OUT2; OUT3}
I am also attaching the file, which I want to uplaod into the table.
Does anyone know how to uplaod it, I also tried " set command" but it is giving me error
"Error using matlab.ui.control.Table/set
Error setting property 'Data' of class 'Table':
Data within a cell array must have size [1 1]
Do anyone has an idea..?


Sign in to comment.

Accepted Answer

Rohith Nomula
Rohith Nomula on 15 Jun 2020
Edited: Rohith Nomula on 15 Jun 2020
load it normally
yourfile = load('GlobalSystemMatrices.mat')
yourtable = struct2table(yourfile)
that way you get a 3 column table which you can directly include it in the UI
UITable.Data = yourtable

  1 Comment

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!