Save data in cell using get function
Ältere Kommentare anzeigen
Hi everyone, I've some issue in saving some tables I create in App Designer. The app doesn't have any uitab or uitable(parent of uitab), but they're created at the startup of the app by defining their properties. Their multiplicity depends on the file .mat from which data are loaded. Table 1 is stored in t{1}, table 2 in t{2} and so on. I don't really know if this is a smart way to reach my goal, but it makes me quite flexible in the management of the new tables are added within the app and leaving the buttons functions work. By the way, whenever I try to save the tables (eventually more than the previous number of tables), only the last table saved contains the data, whereas the previouses are shown as empty arrays. I tried several methods in order to store data from this kind of variable, but the function "get" seems the only one able to do it unless this inconvienece.
Thanks everybody who could help me.
function startupFcn(app)
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [16 248 820 220];
% Load file
loadfile = load('path\score_data.mat');
% Create tabs cell
app.tabs = cell(1,length(loadfile));
for i=1:length(loadfile)
app.tabs{i} = uitab(app.TabGroup,'Title',['Semester ' num2str(i)]);
end
% Add tables
app.tables = cell(1,length(loadfile));
for i=1:length(loadfile)
uit = uitable('Parent',app.tabs{i},'CellEditCallback',@(event,lbl)cellchanged(app));
uit.ColumnWidth = {'auto',125,125,100};
uit.ColumnName = {'Subject','Uniwhere Average','My Score','Weight'};
uit.ColumnEditable = true;
uit.RowName = {};
uit.Position = [15,15,790,170];
app.tables{i} = uit;
app.tables{i}.Data = loadfile.t{i};
end
end
...
function SaveTableScoresButtonPushed(app, event)
t = cell(1,length(app.tables));
t{1} = get(app.tables{1},'Data');
t{2} = get(app.tables{2},'Data');
% for i=1:length(app.tables)
% t{i} = get(app.tables{i},'Data');
% end
save('path\score_data.mat',"t")
end
Antworten (1)
Jan
am 5 Mär. 2022
I'm not sure, if I understand, what you are asking for.
This part of the code looks strange:
app.tables = cell(1, length(loadfile));
for i = 1:length(loadfile)
...
app.tables{i}.Data = loadfile.t{i};
end
It looks like loadfile is a scalar and the actual data are stored in the array loadfile.t. So maybe you mean:
app.tables = cell(1, length(loadfile.t));
% ^^
for i = 1:length(loadfile.t)
% ^^
...
app.tables{i}.Data = loadfile.t{i};
end
3 Kommentare
Luca Reali
am 5 Mär. 2022
Jan
am 6 Mär. 2022
"The issue is that in the cell "t" happens to save only the data of app.tables{i} in t{i}, whereas all the previous cells are empty." - what is "i" in this statement?
Which code are you using? The code you have posted contains an access of "t{i}" only in the comments.
Your mlapp does not open in my Matlab version. Prefer to post the code as text instead.
Luca Reali
am 6 Mär. 2022
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!