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 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!