Saving data after pressing SAVE button in GUI MATLAB
조회 수: 8 (최근 30일)
이전 댓글 표시
I have five push buttons. The four pushbuttons are associated with different datas like for eg one is for age of female and their corresponding weight. Pushbutton2 is associated with data for age of male and their weight. Similarly pushbutton3 and pushbutton 4 relates to other data. There is also a SAVE pushbutton. When I press pushbutton1 and after that press SAVE pushbutton, I should be able to browse my system and give path for saving data in excel file. Similarly, I should be able to do for all other pushbuttons as well. I am not getting idea how to denote that one particular pushbutton is pressed. I was thinking of changing the background color of the button when I press it and relate it using if-else statement. I want my code in the SAVE button callback function sthg to be like:
If pushbutton1 is pressed
\\extract data, give directory and save data
else if pushbutton2 is pressed
\\extract data, give directory and save data
else if pushbutton3 is pressed
\\extract data, give directory and save data
else if pushbutton4 is pressed
\\extract data, give directory and save data
댓글 수: 2
Geoff Hayes
2022년 6월 23일
@Sush Gautam - what does pressing the buttons (1-4) actually do? Is something loaded? Are variables populated? You may want to add some sort of common behaviour to all four buttons so that it doesn't matter which button was pressed when you then press "save". i.e. you could save the data to one more variables (array, etc.) and then those variables would be used when saving to file.
채택된 답변
Image Analyst
2022년 6월 23일
I don't think you wouldn't do that. Each button will have a callback function, which is code that gets run when you push the button. In the callback function you would have code like this:
% Get the name of the file that the user wants to save.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = userpath % Or "pwd" or wherever you want.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
% Now save the data using some function.
If you have any more trouble, attach your .mlapp file, or your .fig and .m file (if using GUIDE).
댓글 수: 2
Image Analyst
2022년 6월 23일
You are not supplying us with enough information. How do I know what your data are? And how do I know how they are to be used in creating the filename? And how do I know if you want to create a default filename and ask the user for confirmation, or just go ahead and save it with the filename you made without asking the user for confirmation?
To save you can use writematrix or writecell or writetable depending on what the form of the data you want to write is.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!