GUI table values to textfile - Cannot find a solution

조회 수: 6 (최근 30일)
Rahul Pillai
Rahul Pillai 2017년 11월 5일
답변: Jan 2017년 11월 6일
I wanna save a cell array created in the opening function of a gui when the user clicks a save button in the gui. I am not able to do this. Here is my code, please tell me what lines to add to successsfully save the variables PPM, GFD and ESS into a single textfile as shown:
function postprocess_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to postprocess (see VARARGIN)
Fg = varargin{1};
Ug = varargin{2};
eps = varargin{3};
sig = varargin{4};
elems = varargin{5};
L = varargin{6};
A = varargin{7};
E = varargin{8};
i=1:3;
PPM=[i.',elems(i,1:2),L(i,1),A(i,1),E(i,1)];
j=1:6;
GFD=[j.',Fg(j,1),Ug(j,1)];
k=1:3;
ESS=[k.',eps(k,1),sig(k,1)];
set(handles.uitable1,'Data',PPM);
set(handles.uitable4,'Data',GFD);
set(handles.uitable6,'Data',ESS);
% Choose default command line output for postprocess
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
and MY CALL BACK FUNCTION IS:
function savebutton_Callback(hObject, eventdata, handles)
% hObject handle to savebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uiputfile({'*.txt';'*.*'}, 'Save as');
if isequal(filename,0) || isequal(pathname,0)
disp('User selected Cancel')
else
disp(['User selected ',fullfile(pathname,filename)])
path_file=fullfile(pathname,filename)
a=fopen(path_file,'wt');
fclose('all')
if filename < 0
error('Failed to open file "%s" because "%s" was not given name:', filename, msg);
end
ppmout=cell2table(get(handles.PPM,'Data'));
writetable(ppmout, path_file);
end
I am going through several problems but mainly issues like "Reference to non-existent field 'PPM'" and also that when I try to write stuff from the uitable into text file, it generates error saying 'cannot "write" from a table of type double' while using writetable()
  댓글 수: 1
Jan
Jan 2017년 11월 6일
편집: Jan 2017년 11월 6일
Please post the failing code and a complete copy of the error message. A shorter rephrased version is less useful.

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

답변 (1개)

Jan
Jan 2017년 11월 6일
Avoid "fclose(all)" but close the specific file directly by fclose(a).
"if filename < 0" is not meaningful here. What is its purpose?
The error message is clear: The struct handles does not contain the field "PPM". Perhaps you want to defined it in the OpeningFcn:
handles.PPM=[i.',elems(i,1:2),L(i,1),A(i,1),E(i,1)];

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by