Re: GUI - reopening previous run
- From: "Jason " <j_henderson44@xxxxxxxxxxxxxxxxx>
- Date: Wed, 9 Jan 2008 15:18:02 +0000 (UTC)
"Anh Huy Phan" <phananhhuy@xxxxxxxxxxxxx> wrote in message
<fm2ik1$pn3$1@xxxxxxxxxxxxxxxxxx>...
Yes this is the way I have been trying to do it. However I
am not sure how to load the user-defined values (saved from
last run) instead of my default values.
Something likes that-
Check the existence of your user-defined data file,
If yes, load this file, and set values to your control
objects.
Otherwise, set them by default values.
datafile = 'uservals.mat';
if exist(datafile,'file)==2
%% load your data
uservals = load(datafile);%load(datafile) is also OK
name = fieldnames(data);
%% set user-defined value
set(handles.object1, 'Value',getfield(data,name{1}))
....
else
%% set default value
set(handles.object1, 'Value',value1)
...
end
In the uicontrol for the variable I have a box for"string".
This is the value I have when the GUI opens. How do Idirect
this string to the variable from the workspace/file?
Do you want to get and assign the string in the edit text to
one variable in the workspace???
obj = findobj('parent',gcf,'style','edit');
str = get(obj,'String');
also you could use the functions assignin and evalin.
Anh Huy Phan
RIKEN - BSI
Hello Anh Huy Phan and thank you for your help.
I am still struggling to implement this. I have been using
SIMULINK so I am only a novice on GUI.
I am now trying to do my task with a more simple GUI. In
mygui.fig I have two variables.
To execute my gui I have directed a pushbutton to a .m file
in the callback uicontrol. so I have a .m file with the lines
_____________________________
%notice that this m-file is NOT a function because
%simulink only allows you to use variables that are within
the main
%workspace
clear all
%make the handles structures available to the main workspace
h =gcf;
handles = guidata(h);
%set the axes to which the data will be plotted to
axes(handles.axes1);
datafile = 'workspace.mat'
if exist(datafile,'file')==2
load(datafile)
end
% get the parameters from the edit text fields
mass=str2num(get(handles.mass,'String'));
%simulate the system
sim('testmodels');
___________________________________
This creates the variable in workspace to pass to SIMULINK.
As you can see I have added your lines of code. However I am
not sure if I should add your other code here or in mygui.m
As you can see I get the parameters from the edit text field
so I just need to set up the if loop correctly. Should I set
it up here or in the mygui.m file. I am not sure of best
practice. Therefore I am not sure how to implement your code
below? Any advice is appreciated.
Thanks
name = fieldnames(data)
set(handles.object1, 'Value',getfield(data,name{1}))
else
set(handles.object1, 'Value',value1)
end
_____________________________________
function mass_Callback(hObject, eventdata, handles)
% hObject handle to mass (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of mass as text
% str2double(get(hObject,'String')) returns contents
of mass as a double
% --- Executes during object creation, after setting all
properties.
function mass_CreateFcn(hObject, eventdata, handles)
% hObject handle to mass (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
.
- Follow-Ups:
- Re: GUI - reopening previous run
- From: Anh Huy Phan
- Re: GUI - reopening previous run
- References:
- GUI - reopening previous run
- From: Jason
- Re: GUI - reopening previous run
- From: Anh Huy Phan
- Re: GUI - reopening previous run
- From: Anh Huy Phan
- GUI - reopening previous run
- Prev by Date: Re: Plot trajectories on a sphere?
- Next by Date: Re: decimal
- Previous by thread: Re: GUI - reopening previous run
- Next by thread: Re: GUI - reopening previous run
- Index(es):