Saving data after pressing SAVE button in GUI MATLAB

18 visualizzazioni (ultimi 30 giorni)
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 Commenti
Geoff Hayes
Geoff Hayes il 23 Giu 2022
@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.
Sush Gautam
Sush Gautam il 23 Giu 2022
the pushbuttons from 1-4 consists of different datas... although all of them associate with common heading (suppose age and weight but the data value differ when you press their repective buttons. I still don't get it that how am I suppose to save those data individually different excel file when I press that particular button. Te above code only gives the path to save data but does not save any data

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 23 Giu 2022
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 Commenti
Sush Gautam
Sush Gautam il 23 Giu 2022
the pushbuttons from 1-4 consists of different datas... although all of them associate with common heading (suppose age and weight but the data value differ when you press their repective buttons. I still don't get it that how am I suppose to save those data individually different excel file when I press that particular button. Te above code only gives the path to save data but does not save any data
Image Analyst
Image Analyst il 23 Giu 2022
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:

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by