Creating a Save button

조회 수: 10 (최근 30일)
Samuel
Samuel 2024년 10월 19일
댓글: Walter Roberson 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개)

Gojo
Gojo 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')

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

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by