Effacer les filtres
Effacer les filtres

save the output data of GUI

9 vues (au cours des 30 derniers jours)
RJS
RJS le 29 Nov 2021
Commenté : Jan le 1 Déc 2021
I am testing the number of data file in my GUI, Now I want to store the output data of each file . My question is how can i incrementally save the output on a list.
Kp = getappdata(0,'Kp')
Kr = getappdata(0,'Kr')
if exist('myData.mat','file')
S=load('myData.mat');
gain=S.gain;
else
gain = struct('Kp','Kr');
gain.Kp = Kp;
gain.Kr = Kr;
end
save('myData.mat','gain');
it just stores the first data,,,please help

Réponse acceptée

Jan
Jan le 29 Nov 2021
Modifié(e) : Jan le 29 Nov 2021
Kp = getappdata(0, 'Kp');
Kr = getappdata(0, 'Kr');
if isfile('myData.mat') % older: exist('myData.mat','file')
S = load('myData.mat');
gain = S.gain;
gain.Kp(end + 1) = Kp;
gain.Kr(end + 1) = Kr;
else
gain.Kp = Kp;
gain.Kr = Kr;
end
save('myData.mat', 'gain');
Hints:
  • Store the data inside the GUI instead of the root object, where they are shared with all other applications, which write to the root object. This has the same drawbacks as using global variables.
  • Do not rely on the current folder. A user can change the current folder, or a callback of the GUI. So add a specific folder to the file, e.g.
myPath = fileparts(mfilename('fullpath'));
file = fullfile(myPath, 'myDFata.mat');
if isfile(file)
S = load(file);
... etc.
end
Using absolute path names is safer.
  4 commentaires
RJS
RJS le 1 Déc 2021
I mean can I save this variable in excel sheet?
Jan
Jan le 1 Déc 2021
Yes, of course.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by