How do I save using the App 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 50x9 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.

7 个评论

So I have got it saving but it's not exactly what I want..
function SaveButtonPushed(app, event)
app.File.NewData = app.File.Data;
NewData = app.File;
save('NewDataFile','-struct','NewData');
end
The issue is when I open the NewDataFile.mat I get both the old and the new Data.. Whereas I only want the old data..
I suppose I could just overwrite my first line to read
app.File.data = app.File.data; % Having made changes to the data
Robert - I'm not sure I understand but you say that The issue is when I open the NewDataFile.mat I get both the old and the new Data.. Whereas I only want the old data. If you only want the old data, then can't you just load the 'data.mat" that only has the old data in it?
Sorry long day.
I was meant to say I only want the new data.
So the app, loads in old data. Which is a .mat file that is a 50x9 table
Presses "Edit Button" To make new data. (This is functionality which I will add later, for now lets say make column 2 all 0)
Press "Save button" which will only save the New data, as a .mat file which is a 50x9 table
hmmm...how do you determine what is old data and what is new? Do you allow the user to edit or delete the old data or just add new data to the table? If the latter, then you should be able to determine where the new data starts in the table (assuming that the user or the code doesn't switch the order of new and old rows).
So at the moment we have,
app.File.Data which is what we have loaded in. So that initial 50x9 table is held in Data
What I want is the edited data to be in app.File.NewData
However you can't seem to be able to save variables. So I have just thought why don't I just make a new property and call it NewFile and then save it?
app.NewFile.NewData
That way I can save it as a seperate .mat file
There seems to be a problem with the App designer that doesn't let you save certain things.
>> clear all
>> app.OldFile = load('batches.mat');
>> app.NewFile = app.OldFile;
>> app.NewFile.batches{:,1} = 1;
>> NewBatches = app.NewFile.batches;
>> save(NewBatches)
This above works perfectly(pretty much) when typed into the command Window.
I get the old 50x9 in OldFile, I make all of column 1 '1', and then I save the new 50x9 table in a NewBatches.mat file.
However I get the error
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects.
when I use it in the App Designer
I have a similar a problem,can you upload your files and data.mat ?I want to learn from them,thank you very much

请先登录,再进行评论。

 采纳的回答

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.

1 个评论

hello , i have a similar a problem where i want to save data for vales added to a UItable , i have also added a separate button and added a property but im not sure on how to save it and plot the new table using scatter plot
properties (Access = private)
sensor_table = gobjects(1,1); %initialize as graphics object
sensor_values
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: RunButton
function RunButtonPushed(app, event)
platewidth=app.WidthEditField.Value;
plateheight=app.HeightEditField.Value;
GridWidth = app.GridWidthEditField.Value;
GridHeight = app.GridHeightEditField.Value;
Xcoordinate = app.XcoordinateEditField.Value;
Ycoordinate = app.YcoordinateEditField.Value;
Lengthofcell = app.LengthofcellEditField.Value;
Gridx = Xcoordinate : Lengthofcell : GridWidth+Xcoordinate;
Gridy = Ycoordinate : Lengthofcell : GridHeight+Ycoordinate;
if Gridx(end) >= platewidth
error('Grid x (%d) + grid width (%d) >= plate width (%d)', Xcoordinate, GridWidth, platewidth);
end
if Gridy(end) >= plateheight
error('Grid y (%d) + grid height (%d) >= plate height (%d)', Ycoordinate, GridHeight, plateheight);
end
Mx = length(Gridx);
My = length(Gridy);
[x, y] = meshgrid(Gridx, Gridy);
%create the list of text
labels = string(1:Mx*My).';
%insert the labels
hold(app.UIAxes, 'on')
scatter(app.UIAxes, x, y, "O", "MarkerFaceColor", 'r')
text(app.UIAxes, x(:), y(:), labels, 'HorizontalAlignment', 'left', 'verticalalignment', 'bottom')
%calculte the grid lines
grid1x = [Gridx;Gridx];
grid1y = [Gridy(1); Gridy(end)];
grid2x = [Gridx(1); Gridx(end)];
grid2y = [Gridy; Gridy].';
plot(app.UIAxes, grid1x, grid1y, "Color", 'b');
plot(app.UIAxes, grid2x, grid2y, "Color", 'b');
rectangle(app.UIAxes, 'Position', [0 0 platewidth plateheight],'LineWidth', 5);
box(app.UIAxes, 'on')
grid(app.UIAxes, 'on')
xlim(app.UIAxes,[0 platewidth])
ylim(app.UIAxes,[0 plateheight])
xticks(0:Xcoordinate:platewidth)
yticks(0:Ycoordinate:plateheight)
hold(app.UIAxes, 'off')
N = app.NoofSensorsEditField.Value;
sensor_number = (1:N).';
X_coordinate = zeros(N,1);
Y_coordinate = zeros(N,1);
T = table(sensor_number, X_coordinate, Y_coordinate);
app.sensor_table = uitable(app.UIFigure, 'Data', T);
app.sensor_table.ColumnEditable = true;
end
% Button pushed function: AddButton
function AddButtonPushed(app, event)
app.sensor_values=uitable(app.UIFigure, 'Data', T);

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by