run simulink with GUI with set_param()

1 次查看(过去 30 天)
sia
sia 2013-5-10
Hi,
i wanna to edit 2 values in the GUI and with one button the simulnk gets these values and after the result should be displayed in the GUI.
but i dont understand set_param(). this is my code:
if true
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
% --- Executes just before Gui is made visible.
function Gui_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for Gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gui_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
function kraft_Callback(hObject, eventdata, handles)
kraft_value = str2num(get(hObject,'String'));
if (isempty(kraft_value))
set(hObject,'String','0')
end
guidata(hObject, handles);
function flaeche_Callback(hObject, eventdata, handles)
flaeche_value = str2num(get(hObject,'String'));
if (isempty(flaeche_value))
set(hObject,'String','0')
end
guidata(hObject, handles);
function start_Callback(hObject, eventdata, handles)
k = str2num(get(handles.kraft,'String'));
f = str2num(get(handles.flaeche,'String'));
set_param('Steifigkeit/k','String',num2str(k));
set_param('Steifigkeit/f','String',num2str(f));
set(handles.static,'String',spannung);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function static_CreateFcn(hObject, eventdata, handles)
end
But i dont know what is the meaning of the parameters os set_param(). cann you help me pls?
  1 个评论
Rohit
Rohit 2013-6-27
Hi, I am trying to use set_param for changing 'Initial output' parameter of 'Ramp' block.
I am doing this by using:
global a1
set_param([bdroot '/BR-KT Assembly-1/Motion input2/Ramp1'],'Slope',a1)
But it gives me an error message saying: Error using GUI_Rohit>StartSimulation_Callback (line 429) Ramp block (mask) does not have a parameter named 'Initial output'
Can you suggest something to eliminate this?
Thanks a lot
Rohit

请先登录,再进行评论。

回答(3 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-5-10
set_param allows to change any parameters block in your simulink model
Look at set_param

sia
sia 2013-5-10
I know this link, but i dont understand set_param(object,param,value) the objektname is the name of my .mdl ??
and what is param???
e.g. i have written
set_param('Steifigkeit','String',num2str(k));
where can i finde the name of my param????
  1 个评论
Kaustubha Govind
Kaustubha Govind 2013-5-10
Sia: Not sure I understand your question. In this case, 'String' is the name of the parameter you are trying to set. Is that what you're asking?

请先登录,再进行评论。


sia
sia 2013-5-10
yes, it should be the name, but that is false "String". it should be what else, but i tried all of my parameters, but they are not the right name :(. how can i finde the right parameter ?
  5 个评论
Rohit
Rohit 2013-6-27
Thanks a lot... that answered my question

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by