how can i sync simulink model with gui? i tried several functions but it nothing heppend still there is problem. i tried SET_PARAM but no result. could any one tell me the proper solution how can i update this problem????????

 Accepted Answer

what do you actually mean with synchronization with GUI?
Do you want to update GUI values/graphs based on Simulink model when the model is running? Then you may want to check this demo ( Event Llstener )
Do you want to update/set Simulink model parameter using the GUI? then the set_param/get_param is the correct way to proceed.

9 Comments

Dear Ilham Hardy
Yes I want to update simulink model parameters values with the help of GUI. I used set_param but it is not working if you give me some examples that will really much more kind of you.
Md Abu Bakar Siddique
It is very useful for us to know: -
  • How do you call the set_param command
  • What is the error message? Put the error message in full (copy/paste the red warning letter when error occured).
instead of saying 'it's not working'.
For chronological discussion, I moved your answer here..
here is the code for updatine the sinewave value in gui
function edit_mag_Callback(hObject, eventdata, handles) % hObject handle to edit_mag (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 edit_mag as text % str2double(get(hObject,'String')) returns contents of edit_mag as a double handles=guidata(hObject); val=get(hObject,'string'); set(handles.slider_mag,'value',str2double(val)); set(handles.Matlab_simulink/SineWave/Amplitude,'Amplitude',num2str(val));
set_param(Matlab_simulink/SineWave/Amplitude,'Amplitude',val); %set_param(Matlab_simulink/SineWave/Amplitude,'SineWave',val); %set_param(Matlab_simulink,'Matlab_simulink/SineWave/Amplitude','Amplitude','value'); guidata(hObject,handles);
% --- Executes during object creation, after setting all properties. function edit_mag_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_mag (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
% --- Executes on slider movement. function slider_mag_Callback(hObject, eventdata, handles) % hObject handle to slider_mag (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider val=get(hObject,'value'); %put the value to text
set(handles.edit_mag,'string',val); %Update SIM model %set_param(Matlab_simulink/SineWave/Amplitude,'Amplitude',val); set_param(Matlab_simulink/SineWave/Amplitude,'SineWave',val); guidata(hObject,handles);
•here is the error message *
Undefined function or variable 'SineWave'.
Error in Simulink_Gui1>slider_mag_Callback (line 186) set_param(Matlab_simulink/SineWave/Amplitude,'SineWave',val);
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in Simulink_Gui1 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Simulink_Gui1('slider_mag_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
thank you very much its really done thanks again. and i want to know something more. could you please help me for updating this. i want to make gui controlled based phase shifted full bridge dc dc converter in simulink programming with dspic tools. if you have some staff which will be more helpful for me to do this project.that will be kind of you
Mohammad,
I noticed several error on your script. I think it will be useful for you to first understand the documentation on set_param command. You can call this by typing:
doc set_param
in the command window. There are several examples in the documentation i.e. how to set block parameter value. See below:
vdp
set_param('vdp/Mu','Gain','10')
The first command ( vdp ) opens model called vdp. The second command consists of three inputs, the first input indicates the 'address' of the block parameter ( Mu is how the Gain block is labeled, so basically you gives command to find Gain block called Mu in the vdp model).
Second input represents the block specific parameter. It indicates which value you want to change. In your script, i think that you want to change the amplitude value. In this case, you need to use 'Amplitude' for the second input. These block specific parameter documentation can be found here
The third input is the set value. Say you want to change the amplitude value to 10. Then you need to put '10' for third input. Pay attention that the third input need to be in strings format, hence the quotation mark required before and after the value.
Lastly, there are so many examples/demos available on the Matlab/Simulink manuals. One that matched your question is probably this one
Hope that helps, Ilham
Ilham Thanks for your helping. i want to know is it possible open scope block command in gui. i mean that i want to press scope button in gui and it will autometically open without clicking simulink file. thanks in advance Abu Bakar
Use
open_system()
For example, if your scope block named 'Scope' and located in the top layer of your model (not inside subsystems). Use:
open_system([gcs '/Scope'])
Thanks Ilham
thats a new problem i have. i couldn't find realtime workshop in model configuration parameter in (matlab2013b). i tried but i couldn't. what should i do right now could you please tell me
Regards Abu Bakar
Hi Abu,
Depending on your Matlab version, the Real-time Workshop (RTW) might have been updated to Simulink Coder .
This is a separate toolbox, not included in default Matlab software package. Which also means you have to buy for it separately.
To interface microcontroller with Matlab/Simulink, Embedded Target can be used. However, as far as I know, to use the Embedded Target you need to have Simulink Coder toolbox.

Sign in to comment.

More Answers (2)

Dear Ilham Hardy
Yes I want to update simulink model parameters values with the help of GUI. I used set_param but it is not working if you give me some examples that will really much more kind of you.
Md Abu Bakar Siddique
here is the code for updatine the sinewave value in gui
function edit_mag_Callback(hObject, eventdata, handles) % hObject handle to edit_mag (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 edit_mag as text % str2double(get(hObject,'String')) returns contents of edit_mag as a double handles=guidata(hObject); val=get(hObject,'string'); set(handles.slider_mag,'value',str2double(val)); set(handles.Matlab_simulink/SineWave/Amplitude,'Amplitude',num2str(val));
set_param(Matlab_simulink/SineWave/Amplitude,'Amplitude',val); %set_param(Matlab_simulink/SineWave/Amplitude,'SineWave',val); %set_param(Matlab_simulink,'Matlab_simulink/SineWave/Amplitude','Amplitude','value'); guidata(hObject,handles);
% --- Executes during object creation, after setting all properties. function edit_mag_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_mag (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
% --- Executes on slider movement. function slider_mag_Callback(hObject, eventdata, handles) % hObject handle to slider_mag (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider val=get(hObject,'value'); %put the value to text
set(handles.edit_mag,'string',val); %Update SIM model %set_param(Matlab_simulink/SineWave/Amplitude,'Amplitude',val); set_param(Matlab_simulink/SineWave/Amplitude,'SineWave',val); guidata(hObject,handles);
  • here is the error message *
Undefined function or variable 'SineWave'.
Error in Simulink_Gui1>slider_mag_Callback (line 186) set_param(Matlab_simulink/SineWave/Amplitude,'SineWave',val);
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in Simulink_Gui1 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Simulink_Gui1('slider_mag_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

Categories

Community Treasure Hunt

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

Start Hunting!