Creating a Save button
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Shubham
le 19 Oct 2024
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 commentaires
Walter Roberson
le 19 Oct 2024
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')
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!