Creating a Save button

8 次查看(过去 30 天)
Samuel
Samuel 2024-10-19
I am currently creating an app in matlab to perform some calculations. I am looking for a a work to create a save button that saves all inputs and outputs into a text file. Any help would be much appreciated.

回答(1 个)

Shubham
Shubham 2024-10-19
Hey Samuel,
In order to create a save button in a MATLAB app to save inputs and outputs to a text file, you can make use of callback functions in App designer. Here is a simple way to create callbacks in App Designer:
function codeButtonResponse
fig = uifigure('Position',[500 500 300 200]);
btn = uibutton(fig,'ButtonPushedFcn',@buttonCallback);
function buttonCallback(src,event)
disp('Button pressed');
% Your code to retreive the desired variables and save in a file
end
end
Once you create a simple callback function, all you have to do is access the variables you wish to save and store them in a file, for example a .MAT file.
You can access the input and output fields to get the desired values and save them in a file, for example:
a = app.editfield1.Value;
b = app.editfield2.Value;
save('pathtomat.mat','a','b');
I hope this would give you some hints to create a save button in your app.
  2 个评论
Samuel
Samuel 2024-10-19
Thank you very much for your help. It has worked. But is the anyway to save the inputs and outputs in a text file instead OF.mat
Walter Roberson
Walter Roberson 2024-10-19
a = app.editfield1.Value;
b = app.editfield2.Value;
data_to_save = [a; b];
writematrix(data_to_save, 'OutputFileNameGoesHere.txt')
However, you would probably want something closer to
a = app.editfield1.Value;
b = app.editfield2.Value;
data_to_save = {'a', a; 'b', b};
writecell(data_to_save, 'OutputFileNameGoesHere.txt')

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by