save the output data of GUI

10 次查看(过去 30 天)
RJS
RJS 2021-11-29
评论: Jan 2021-12-1
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

采纳的回答

Jan
Jan 2021-11-29
编辑:Jan 2021-11-29
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 个评论
RJS
RJS 2021-12-1
I mean can I save this variable in excel sheet?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by