Error using set_param to set parameters for LUT from inside a function in GUI
3 views (last 30 days)
Show older comments
I am using set_param to set the parameters of Look Up Table block from simulink library. The parameters are 'Table' and 'BreakpointsForDimension1'. i am able to set the values for 'Table' correctly, but some error occurs for the other parameter.Let me also explain the context:
I want to restore the state of GUI, meaning GUI should show the past values entered by user in his last session.For this, in the close pushbutton, i call saveState function:
function saveState(handles)
state.tumblingOpt3SpeedVector = get(handles.edit12, 'String');
state.tumblingOpt3TimeVector = get(handles.edit11, 'String');
state.tumblingOpt3aref1 = get(handles.edit13, 'String');
state.tumblingOpt2td = get(handles.edit3, 'String');
state.tumblingOpt2tz = get(handles.edit4, 'String');
state.tumblingOpt2w = get(handles.edit5, 'String');
state.tumblingOpt2aref = get(handles.edit6, 'String');
save('state.mat','state')
And in the Opening func of GUI, i call loadState function to restore the state of GUI
function loadState(handles)
evalin('base','load state.mat') % To load state.mat into workspace
% To restore the state of GUI
set(handles.edit11, 'String', evalin('base','state.tumblingOpt3TimeVector'))
set(handles.edit12, 'String', evalin('base','state.tumblingOpt3SpeedVector'))
set(handles.edit13, 'String', evalin('base','state.tumblingOpt3aref1'))
set(handles.edit3, 'String', evalin('base','state.tumblingOpt2td'))
set(handles.edit4, 'String', evalin('base','state.tumblingOpt2tz'))
set(handles.edit5, 'String', evalin('base','state.tumblingOpt2w'))
set(handles.edit6, 'String', evalin('base','state.tumblingOpt2aref'))
% To set parameters in simulink block corresponding to what GUI shows
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref','BreakpointsForDimension1',evalin('base','state.tumblingOpt3TimeVector'))
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref','Table',evalin('base','state.tumblingOpt3SpeedVector'))
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/aref1','Value',evalin('base','state.tumblingOpt3aref1'))
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/tumblingProfileOpt2','td', evalin('base','state.tumblingOpt2td'))
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/tumblingProfileOpt2','tz', evalin('base','state.tumblingOpt2tz'))
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/tumblingProfileOpt2','w', evalin('base','state.tumblingOpt2w'))
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/tumblingProfileOpt2','aref', evalin('base','state.tumblingOpt2aref'))
delete('state.mat')
Now let me show some results and observations:
Error Message on running the GUI:
Error using dtc>loadState (line 144)
Error in 'Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref'. Parameter 'BreakpointsForDimension1' setting: "
3 3.24191 3.25 3.999 4 7.24999 7.25 8" cannot be evaluated.
Error in dtc>dtc_OpeningFcn (line 77)
loadState(handles)
Error in gui_mainfcn (line 221)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in dtc (line 42)
gui_mainfcn(gui_State, varargin{:});
Caused by:
Error using dtc>loadState (line 144)
Error: Expression or statement is incomplete or incorrect.
EVEN IF I TYPE SET_PARAM AT THE COMMAND LINE,I GET THE SAME ERROR, AS FOLLOWS:
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref','BreakpointsForDimension1', evalin('base','state.tumblingOpt3TimeVector'))
Error in 'Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref'. Parameter 'BreakpointsForDimension1' setting: "
[3 3.24191 3.25 3.999 4 7.24999 7.25 8]" cannot be evaluated.
Caused by:
Error: Expression or statement is incomplete or incorrect.
But this error is not there for parameter 'Table' either while running GUI or at command line:
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref','Table', evalin('base','state.tumblingOpt3SpeedVector'))
get_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref','Table')
ans =
[40 40 0 0 -40 -40 0 0]
BUT MOST IMP OBSERVATION IS THIS ONE:
after the state.mat is loaded into workspace...if i open the 'state' variable in workspace,it lists:
tumblingOpt3SpeedVector: '[40 40 0 0 -40 -40 0 0]'
tumblingOpt3TimeVector: <1*40 char>
and others.......
Why tumblingOpt3TimeVector is not taken as an array like tumblingOpt3SpeedVector?
Please post ur valuable suggestions
thanks
0 Comments
Answers (1)
Kaustubha Govind
on 2 May 2013
I think the issue may be that most Simulink parameters need to be set as strings when using set_param. For example, this won't work:
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref','BreakpointsForDimension1', [3 3.24191 3.25 3.999 4 7.24999 7.25 8])
But, this will:
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref','BreakpointsForDimension1', '[3 3.24191 3.25 3.999 4 7.24999 7.25 8]')
Why not simply set:
set_param('Sensorless_DTC_HwAnalysis/Tumbling_profiles/wref','BreakpointsForDimension1', 'state.tumblingOpt3TimeVector')
And let Simulink read the parameter from the base workspace? If you are running the SIM command from a GUI callback, make sure that you set the SrcWorkspace to 'base':
options=simset('SrcWorkspace','base');
sim('Sensorless_DTC_HwAnalysis',[0 duration],options);
2 Comments
Shyam
on 3 May 2013
Edited: Shyam
on 3 May 2013
I had tried that...but since 'state' is not defined in the workspace of that particular function (loadState(handles)) inside which set_param is used...there was error message something like 'state' not defined..thats why i used evalin...
But its working now...i just retyped the array in GUI....but i am afraid error will resurface sooner or later...
Now when state.mat is loaded into workspace...if i open the 'state' variable in workspace,it lists:
tumblingOpt3SpeedVector: '[40 40 0 0 -40 -40 0 0]'
tumblingOpt3TimeVector: '[.........................]'
both as arrays
Kaustubha Govind
on 3 May 2013
Shyam: The error about 'state' being undefined is exactly why I recommend using the simset with your sim command.
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!