Borrar filtros
Borrar filtros

save the output data of GUI

9 visualizaciones (últimos 30 días)
RJS
RJS el 29 de Nov. de 2021
Comentada: Jan el 1 de Dic. de 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

Respuesta aceptada

Jan
Jan el 29 de Nov. de 2021
Editada: Jan el 29 de Nov. de 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 comentarios
RJS
RJS el 1 de Dic. de 2021
I mean can I save this variable in excel sheet?
Jan
Jan el 1 de Dic. de 2021
Yes, of course.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by