Creating a Save button
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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 个评论
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')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!