How do I save using the App Designer

조회 수: 139 (최근 30일)
Robert Jack
Robert Jack 2020년 6월 1일
댓글: Debt 2021년 7월 24일
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
Robert Jack
Robert Jack 2020년 6월 1일
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
Debt
Debt 2021년 7월 24일
I have a similar a problem,can you upload your files and data.mat ?I want to learn from them,thank you very much

댓글을 달려면 로그인하십시오.

채택된 답변

Robert Jack
Robert Jack 2020년 6월 1일
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
Jeet Shetty
Jeet Shetty 2021년 7월 23일
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개)

카테고리

Help CenterFile 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