Filter löschen
Filter löschen

Error when uploading Cell Array to UI Table in GUI

1 Ansicht (letzte 30 Tage)
Chris Dan
Chris Dan am 15 Jun. 2020
Kommentiert: Chris Dan am 15 Jun. 2020
Hello,
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]);
set(f,'visible','on')
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;
else
BodyData= [BodyData; BodyDataAdd];
end
for TempIndex= 1:k
if k==1
AssemblyData{BodyNumber+TempIndex,1} = FileNames;
else
AssemblyData{BodyNumber+TempIndex,1} = FileNames;
end
%AssemblyData{TempIndex,2} = BodyDataAdd{TempIndex,1};
AssemblyData{BodyNumber+TempIndex,2} = BodyData{BodyNumber+TempIndex,1}{1,1};
end
BodyNumber= BodyNumber+k;
set(AssemblyTable, 'Data',AssemblyData);
end
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));
else
for k = 1:length(files)
out{k} = load(fullfile(pathToFiles, files{k}));
end
end
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}
end
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..?

Akzeptierte Antwort

Rohith Nomula
Rohith Nomula am 15 Jun. 2020
Bearbeitet: Rohith Nomula am 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

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by