Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How can I save my data in my editboxes to my .mat file?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
I need a code to save my numbers in my editboxes in gui to my .mat file
This is what I have:
function save_Callback(handles, ~, ~)
[filename, pathname] = uiputfile( ...
{'*.mat';'*.*'}, ...
'Save as');
save(filename, get(handles.edit1));
I've been looking at the other peoples questions to how they do it, and cant seem to see the solution that works for my,
I have named my editboxes: edit1, edit2, edit3, ..... and so on until edit42
what shall I write to get the saved into my .mat file, and do I need a drawnow;?
.
.
.
I've made a simplification:
function varargout = gui(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = gui_OutputFcn(hObject, eventdata, handles)
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function save_Callback(hObject, eventdata, handles)
[filename, pathname] = uiputfile( ...
{'*.mat';'*.*'}, ...
'Save as');
save(filename, get(handles.edit1,'String'));
function load_Callback(hObject, eventdata, handles)
[filename pathname] = uigetfile('*.mat','Select the MATLAB code file');
L = load( fullfile( pathname, filename ) );
But this doesn't work, I get the error:
Error using save
'23' is not a valid variable name.
I put 23 into the editbox and tried to save it.
0 Kommentare
Antworten (1)
David Kusnirak
am 19 Apr. 2013
Bearbeitet: David Kusnirak
am 19 Apr. 2013
Hi,
if you want to get the written value in the edit box you should use
save(filename, get(handles.edit1,'value'));
the field is updated immediately after you write the value into your GUI
3 Kommentare
David Kusnirak
am 19 Apr. 2013
Did you use GUIDE to create your gui or did you design your gui by programming? Because it seems, that you do not have the handle of the editbox in the 'handles' variable
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!