How to set simulink block parameters (customized) from GUI

조회 수: 3 (최근 30일)
chiara cimino
chiara cimino 2018년 11월 14일
편집: chiara cimino 2018년 11월 14일
Hi, I want to do this: in simulink I have included an entity generator block (from the SimEvents toolbox), in entity generator I wrote this matlab code:
persistent rngInit;
if isempty(rngInit)
seed = 2346;
rng(seed)
rngInit=true;
end
% Exponential inter-arrival time dt
mean = 1/10;
dt = -mean*log(1-rand());
Then I created a GUI and from that I want to change the value of the parameter 'seed' inside the previous code and to do so I created in the GUI this callback:
function seed_Callback(hObject, eventdata, handles)
% hObject handle to seed (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 seed as text
% str2double(get(hObject,'String')) returns contents of seed as a double
value=get(handles.seed,'string');
string1=value{1};
load_system('modelloPerProve');
set_param(['modelloPerProve/Entity Generator/Entity generation'],'seed',string);
It runs but it doesn't work. I can't undersatand how to reach the parameter.
Thanks for your help,
Chiara Cimino.

채택된 답변

ES
ES 2018년 11월 14일
I think you should remove assigning value to seed in your model.
persistent rngInit;
if isempty(rngInit)
%seed = 2346;
rng(seed)
rngInit=true;
end
% Exponential inter-arrival time dt
mean = 1/10;
dt = -mean*log(1-rand());
and set the value of seed in base workspace using your gui callback.
function seed_Callback(hObject, eventdata, handles)
% hObject handle to seed (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 seed as text
% str2double(get(hObject,'String')) returns contents of seed as a double
value=get(handles.seed,'string');
string1=value{1};
load_system('modelloPerProve');
evalin('base','seed = 1234')
  댓글 수: 1
chiara cimino
chiara cimino 2018년 11월 14일
편집: chiara cimino 2018년 11월 14일
But I want to change the seed value from the gui with the number inserted by an operator in the edit text box.
do you know how to do it?
thank you,
Chiara

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by