GUI table values to textfile - Cannot find a solution
7 views (last 30 days)
Show older comments
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 Comment
Answers (1)
Jan
on 6 Nov 2017
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)];
0 Comments
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!