MATLAB: How to save using the App Designer

appapp designer

Hi, i've been struggling trying to get app designer to load in and then save a .mat file.
Loading in is fine.
function LoadButtonPushed(app, event)
app.File = load("data.mat");
app.UITable.Data = app.File.data;
end
data.mat is 50×9 table which itself holds additional tables within one column. I can show this data in a table easily enough as I have above.
I shall edit this data at a later point..
My question/problem is that:
All I want to do at the moment is to take this and save it as a seperate .mat file when I press a save button on my App in App Designer. However nothing I seem to do works.
function SaveButtonPushed(app, event)
app.File.Newdata = app.File.data; % Sticks the data into Newdata
%save('NewData.mat','-struct','app.File.NewData')
%save('NewData.mat') % Doesn't work
%save('NewData.mat','app.File.NewData')
%Below I tried to save the structure to a variable and then save it that way
NewData = app.File;
save(NewDataFile,'-struct','NewData');
end
Please if anyone has a solution I would be appreciative as I cannot seem to get it to work.
All I want is another file to be made with the data in.

Best Answer

Got it to work
properties (Access = private)
OldFile % Description

NewFile % Description
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: LoadButton
function LoadButtonPushed(app, event)
app.OldFile = load('batches.mat');
app.UITable.Data = app.OldFile.batches;
end
% Button pushed function: EditButton
function EditButtonPushed(app, event)
app.NewFile = app.OldFile; % works
app.NewFile.batches{:,1} = 1; %works
app.NewFile.NewBatches = app.NewFile.batches;
app.UITable2.Data = app.NewFile.NewBatches;
end
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
%NewBatches = app.NewFile.batches;
%NewBatches = saveobj('NewBatches');
%save('NewBatches')
NewBatches = app.NewFile.NewBatches;
save('NewBatches.mat',"NewBatches")
So I now have two seperate .mat files, one which is the old data and one which is my new edited data.
I am able to add functionality to the number of things I will want to edit within the function EditButtonPushed so i am happy.
Hopefully this helps anyone else who has struggled with the way App Designer saves things.
Related Question