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?
Jan
Jan 2021년 12월 1일
Yes, of course.

댓글을 달려면 로그인하십시오.

추가 답변 (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