필터 지우기
필터 지우기

Error when uploading Cell Array to UI Table in GUI

조회 수: 1 (최근 30일)
Chris Dan
Chris Dan 2020년 6월 15일
댓글: Chris Dan 2020년 6월 15일
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..?

채택된 답변

Rohith Nomula
Rohith Nomula 2020년 6월 15일
편집: Rohith Nomula 2020년 6월 15일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by