Filter löschen
Filter löschen

GUI table values to textfile - Cannot find a solution

1 Ansicht (letzte 30 Tage)
Rahul Pillai
Rahul Pillai am 5 Nov. 2017
Beantwortet: Jan am 6 Nov. 2017
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 Kommentar
Jan
Jan am 6 Nov. 2017
Bearbeitet: Jan am 6 Nov. 2017
Please post the failing code and a complete copy of the error message. A shorter rephrased version is less useful.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 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)];

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by