Matlab GUI Tutorial - Integrating Simulink Model into a GUI
30 Nov 2007 Quan Quach 74 comments 1 views
How to specify other Simulink Parameters through the GUI
Specifying other Simulink Parameters through the GUI is not a difficult task. In this section of the tutorial, I will provide an example on how to do this. You can download the source files here if you do not want to read through the tutorial. Let’s say that we want to add the following capabilities to our GUI:
- set simulation time
- set sample time
- set the time when the unit step occurs
- designate the output parameter names
-
First, let’s make it so the user can specify the simulation time through the GUI. It is possible to specify the start and stop time as an argument to the
simcommand.For example, if I wanted to simulate the model for a specific period of time, I would use the following command:
sim('mass_spring',[0 simTime]);
If no time argument is given, then the value specified within the Simulink Model is used.
Another way of doing this is through the Simulink Model itself. To do this, we need to set the simulation time parameter to a variable. As can be seen in the image, I changed it to
simTime.
-
Next, double click on the “Step” block. Change the Step time field to
stepTimeand the Sample time field tosampleTimeas shown in the image below.
-
Finally, lets change the output block. Previously, the output was called yout by default. But suppose you want to give your output a more descriptive name, like displacement. Instead of using the Out1 sink, we would instead use the To Workspace sink. So go ahead and replace the old output sink with the new one.

-
Finally, we need to modify the properties of the output sink that we just added. Double click on the component and change the Variable name field to
displacementand change the Save format field toArray.
-
The Simulink model should now look like this:

-
Another thing you might want to do is to NOT limit the number of data points that result from your simulation. You can deactivate this by going to Simulation => Configuration Parameters from the Simulink Model.

-
Now, lets move on to the GUI changes. I won’t go over each step. But all we have to do is add on three Static Text Components and three Edit Text Components and to rename their Tag property appropriately. I renamed the Tag property for each of the Edit Text components to: stepTime_editText, sampleTime_editText, and simTime_editText. Here’s what your GUIDE figure should look like after you make the edits:

-
Finally, I made some minor edits to the simulate_pushbutton_Calback function.
function simulate_pushbutton_Callback(hObject, eventdata, handles) axes(handles.axes1) % get the parameters from the edit text fields m=str2num(get(handles.mass_editText,'String')); c=str2num(get(handles.damping_editText,'String')); k=str2num(get(handles.spring_editText,'String')); stepTime=str2num(get(handles.stepTime_editText,'String')); sampleTime=str2num(get(handles.sampleTime_editText,'String')); simTime=str2num(get(handles.simTime_editText,'String')); options = simset('SrcWorkspace','current'); sim('mass_spring',[],options); %plot the data plot(tout,displacement) xlabel('Time') ylabel('Displacement') title('2nd Order Mass Spring System') grid on
-
After you make all of these changes, you can finally test and run your GUI! Try inputting in different input parameters to test it out.

If you are unable to get your GUI/Simulink Model to work, you can download the source files here .
We encourage you explore and to play around with some of the other features within Simulink. There are a myriad of features that were not discussed, and we hope this tutorial has given you a better idea on how to use a GUI in conjunction with Simulink.
This is the end of the tutorial.
74 Responses to “Matlab GUI Tutorial - Integrating Simulink Model into a GUI”
Leave a Reply
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>


I am new to matlab, mainly I work on simulink. I am using Your GUI tutorial to learn GUIDE. All your tutorials are very good and very much explanatory.
In your .m script you used plot (tout, yout), but I don see these variable anywhere neither in the .m file nor in the model. And when I changed these variables name, they were still working fine. Suppose I have one more output port from Gain1 and want to plot (Gain1 Vs time) along with (Displacement Vs time) , want to show to plots in the GUI how should I proceed, shall I use plot(tout, yout) for(Disp. Vs time) and plot(tout, yout1) for (Gain1 Vs time).
It will be great of help if you can put tutorials on simulink GUI integration, like
1. How to integrate Source/Sink block into GUI,
2. How to give option like run, pause, and stop as in simulink in GUI.
3. How to specify step time as in simulink for a model in GUI.
4. How to integrate simulink menu bar some features with GUI like Configuration parameters.
5. How to see output in simulink scope in GUI etc…
Incorporate more of simulink related tutorial into your web w.r.t GUI, as there are very fewer amount of information available.
subin,
I will try to edit the tutorial to answer these questions. Thank you for the feedback!
You can use simset command to change the workspace option for the simulink model.
function runSimulinkModel(m,c,k)
options = simset(’SrcWorkspace’,'current’);
sim(’mass_spring’,[],options);
Chun-Chih,
Thanks for the tip!! That is extremely helpful. I have edited the tutorial to reflect this
Hello,
I need a little help in implementing simulink block via GUI. Ive followed every single steps you had put up, however the gui just doesnt work!!!rather depressed with it….i just couldnt make my simulink block work with gui…
Any tips??
Regards, Reha
Hi reha,
Take a look at the source files and see how it’s implemented, I’m not sure what your specific problem is, so it’s hard for me to help you.
Quan
Heya Quan,
Thanks for the offer. Ive solved the problems now.. Thanks for the tutorial. They were of much help. =D
Thanks,
Reha
Hi,
I am now implement the 555 Astable Simulink model circuit in the MATLAB GUI. After read through your tutorial, I manage to run the simulink model from the GUI. However my circuit model in the simulink is running infinitely, so may I know how can I stop the simulation from the GUI? Based on following code.
% — Executes on button press in stopsimulation_pushbutton.
function stopsimulation_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to stopsimulation_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set_param(handles.Astable_555_timerIC_voltage_measurement_edit, ‘SimulationCommand’, ’stop’)
set_param(’Astable_555_timerIC_voltage_measurement_edit’, ‘SimulationCommand’, ’stop’)
set(handles.text6, ‘String’, get_param(’Astable_555_timerIC_voltage_measurement_edit’, ‘SimulationStatus’))
set(handles.dynamic_plant_state, ‘String’, ’sim stopped’)
set_param(handles.modelname, ‘SimulationCommand’, ’stop’)
set(handles.dynamic_plant_state, ‘String’, ’sim stopped’)
set(handles.play,’value’,0);
set(handles.play,’enable’,'on’);
Besides that, how can I pop up the simulink model that running by GUI when click the “Simulate” button or another button that specially for this function? Based on following code.
% — Executes on button press in design_pushbutton.
function design_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to design_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Thank you for your help.
Hi, I am creating a GUI to interface my model. I want both display my simulation data and plot them. I use ‘to Workspace’ Simulink block to write simulation data on workspace but I am not able to access these data from the GUI and, as a consequence, to plot them in the GUI.
I have also tried to write simulation data in a .mat file but anyway I am not able to visualize these data. I would like to have my data shown in a sort of table in my GUI.
Can you help me?
Hello,
Excellent site and one I keep coming back to for new exercises to master.
I’ve had a look through the tutorials for an example that will return a simulink value to a box in the GUI.
Eg for a simplified value. I want to do 1+1 = 2. So in the GUI I have my two inputs which are sent to simulink to be added. The answer would then be dsiplayed in the GUI.
Is there an example like this so I can see how to pass the simulink answer back to the GUI. I know how to do it with plots so was thinking something similar should be quite easy.
Thanks and keep up the good work.
Hello,
Who would have thought the answer would be in the beginners tutorial for a simpler example.
I amalgamated this example with the simulink GUI example for a solution.
I used the simulatebutton option from the simulink-GUI tutorial and sent the data back to my model like that using the setup from the beginners tutorial. Not the tidiest but it works.
Thanks
I am doing a project on pc based monofilament winder using two stepper motors. And i want to simulate this using matlab simulink. So any body who is volentary to help me please share your idea. Thanks
Thanks for such a nice and easy tutorial thanks it is gonna help me a lot.
You can try using acslx.com software.
perfect !
hello !
I’m trying to implement in a gui a simulink scope, actually there are 4 scopes which i’d like to put on the UI, but I don’t know how.
Is there any possibility to run the finished gui without matlab installed , as a standalone application ??
Thanks alot, Keep UP !!
hello,
im trying to create an GUI where i take the output from the scope (saved in the workspace) to plot it in the GUI axes. the problem is that whenever i simulate the model from the GUI(using a push button) , the workspace variables are not getting updated.
can you help me with this??
Ashwin
Hi,
This is an excellent website and I’ve already learned so much! However, I have a question. Is it possible to change an embedded matlab function variable (in a simulink model) through a GUI?
I am modelling a vairable orifice and would like to change a variable in a a function while the simulation is running. Any help is greatly appreciated!
My model Simulink contains Stateflow blocks, when I start the programme GUI it shows an error:
??? Error using ==> sim
Error reported by S-function ’sf_sfun’ in ‘A_1/Ay (I,y)1/ SFunction ‘:
Stateflow Runtime Error (machine): Error evaluating machine workspace data ‘ks’ in MATLAB base workspace.
MATLAB expression ‘ks’ could not be evaluated.
ks variable is announced as ‘parameter’, if it is announced as ‘Constant’ model works, but ks variable value can be changed only in Simulink, and I need to change it in GUI.
Give me some advice.
Dear Sir,
Thanks for your release.That was realy helpfull. specialy the tutorials,they helped me alotl. Sir i have a little problem in connecting my simulink block to my GUI. In actual my requirement is to get data from my simulink in real time and plot it in real time on my GUI AXES. like on scope of simulink block. Please help me out.
Thanks in advance
Regards,
Bilal
hello sir
i want to implement the block used in the paper”dynamic implementation of MEMS optical switches using simulink”.. am finding difficulty in implementing the block. kindly explain and help me.. its very urgent for my project..
Hi,
Love the tutorials, they have helped me immensely in my project. One problem i can’t solve though is sending the data in real time from simulink to the GUI. My simulink system has a video output that i want to view in a video window from within the GUI. If you have any ideas on this it would help me out immensely.
Thanks
hi….
thanks for your tutorials.
would you post tutorial about making GUI for TSP (Travelling Salesman Problem)?
hai..
I’m a new user of MATLAB..
can anyone help me to make a connection to other pc..
how to show webcam from the other pc in my pc?
I dont know what to do…
hello
I am from Colombia, and have a problem with the funntion sim for begin the simulink,
with the standalone aplication this show an error, ”undifined function sim for param type char”. Please need help.
Thank for you Colaboration.
Hi, great guide
Seeing that I havent work with simulink for a few years and I recently picked it up again, I wonder if you could help me out.
Im trying to alter some of the simulation blocks on my simulated system via a gui, and im talking about the hole block.
Imagine 3 generic blocks linked together with several predetermined inputs and outputs, what I wanted to do is change the system inside each of these blocks by selecting them from a list in my GUI.
Is this even possible?
Yes I beleive it is possible, although I haven’t worked with simulink in a long time as well! I’m sure it can be done though. Good luck, and sorry I could not be of more help
Hi,
I learned how to run simulink from GUI from your posting. I have few comments:
I can run the simulation using following code from gui
The above code does not allow simulation to be paused.
If I want to pause the simulation, I need to use set_param command as follows:
and then associate following code with PAUSE button
but the above code does not allow the option of ‘SrcWorkspace’ being set to ‘current’.
How should I go about it. I do not want the initialisation parameters to be made available to the MATLAb base workspace.
Thanks
hi,
i had a question, i wonder if it is possible to put a picture in the GUI page, to show a diagram or a process for example.
tnx
mitra
hi, would u like to explain on how to integrate simulink models that have base workspace and subsystems with GUI?
example, i wan to output the graph of one of the subsystems on the GUI.
hi, i have a simuink model that have more than ten subsystems.when i run the simulink alone, i have to import data call ‘ptp_diazepam’ to workspace to run the simulink.
I want to try output the graph of 1 of the subsystem which has the output “To workspace” block call Cvt_liver (the variable like in the case of your tutorial,i.e displacement)
i follow your code:
but i got this error:
Error using ==> lisaproj1(’intrabutton_Callback’,gcbo,[],guidata(gcbo))
Error using ==> sim
Unable to open model file ‘genpbpk.mdl’.
hope to hear from you soon! thanks a million
Hi
It was a great tutorial for GUI basics to link to Simulink.
Can you help in one thing though. I want to change my simulink block parameters when the simulation is going on. Is that possible?
If possible how i have to go about it……..
It would be of great help if you can explain this to me…
Thanks for the tutorial again
Ranjan
Hi, I don’t see the parameters ‘tout’ and ‘yout’ in plot(tout, yout); When i run it doesn’t show any graph in GUI, only show the FFT when i run the simulink; can u please help me with it? a little bit confused here. Thank you
Dear Quan,
How can I convert my .mdl file to standalone exe file
hi, this is samra i want matlab gui projects for my project presentation please help me.
Hi ,
I have finished my Matlab GUI and it works as desired. Is it possible make this GUI run as a stand alone application.
Im currently using Matlab 6.0 version. Can u guide me to make this a stand alone application or atleat give me a relavant link for me achieve this objective.
Thx
hi all
does anyone can tell me how i can run VR Sink Block in my simulink model by a pushbutton .
when i doubleclick VR Sink block in my simulink model it run simulation but i was unable to do the same thing using gui.
regards
What’s tout and yout, what’s the meaning of this command : plot(tout,yout)?
Is there any possibility to run the finished gui without matlab installed , as a standalone application ??
You will need MATLAB Compiler. Check out the command deploytool.
Hey,
I am making a GUI, that displays video using Simulink model. I have one problem: I need the video to be shown in the same window as buttons are, in the axes. I can’t find the solution. The video always opens in a separate window. Can anyone help me? I need it as fast as possible, thank you!
Here’s my code:
% — Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
open_system(’dalis2′)
set_param(’dalis2/Gain’,'Gain’,'0′);
sim(’dalis2.mdl’);
% — Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
open_system(’dalis1′)
set_param(’dalis1/Gain’,'Gain’,'0′);
sim(’dalis1.mdl’);
% — Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%closes Simulink models and GUI
close_system(’dalis2′);
close_system(’dalis1′);
close(handles.figure1);
% — Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set_param(’dalis2/Gain’,'Gain’,'1′);
set_param(’dalis1/Gain’,'Gain’,'2′);
Hello,
thanks a lot for your guide tutorial. they have been really helpful and easy to understand.
i have succesfully, integrated my simulink model to GUI, but i would like to know-if possible- how to make plots in the GUI continuous(real time).
thanks for your help in advance.
Hi,
im urgently in need of a response to the last comment by me, please help!. thanks
sir,
i’ve created a simulink model and now i’d like to control it from a GUI. i’ve sucessfully been able to use the set_param command to control simulation.
the problem is that the output of my model is a video and as soon as the simulation starts, it appears in the M-Play video viewer automatically.
I want to embed the video output into the GUI instead. How do i do it??
Hello,
Your tutorials have been of a very great help to me!! kudos to u guys!!
I have a small problem…..I am trying to integrate the status of a checkbox in a GUI with that of a block parameter (for ex: my GUI contains a checkbox and depending on whether it is checked or not I would like to monitor the status of “LOG FIXED-POINT DATA AS A FI OBJECT” of SINK BLOCK PARAMETERS BLOCK) but I could not accomplish the task…hope you could help me out!!
Hello,
I’m trying to simulate my simulink model from the GUI I have created. But when I use the command “sim(’sfunctionxyz’)”, as you explain in the tutorial, the model doesn’t run and the command window print:
??? Simulink model ’sfunctionxyz’ was called with an invalid flag.
??? Error while evaluating uicontrol Callback.
do you have an idea of what matters with the command “sim”?
Hello,
I’m trying to simulate my simulink model from the GUI I have created. But when I use the command “sim(’sfunctionxyz’)”, as you explain in the tutorial, the model doesn’t run and the command window print:
??? Simulink model ’sfunctionxyz’ was called with an invalid flag.
??? Error while evaluating uicontrol Callback.
do you have an idea of what matters with the command “sim”?
I am working on a computer vision project, and I want to display a video sequence, which is the output from a simulink block, in an GUI axes, and I want it to be real-time. I’ve already tried the commands you explained, without succeding. Do you know whether there’s a different way to do want I want?
When I use the sim command, the command window prints: Memory allocation error, pointing to the line in which the sim command is used. Is there any possible solution?
Thanks in advance
yout is the output created in the massspring.mdl file
Hey,
thanks for the tutorial!
Is it possible to get a feedback from Simulink on how far the simulation has proceeded. e.g. implement a progressbar like the one used in simulink to show the simulations progress?
The progressbar itself doesn’t seem so much of a problem, but how do i get information back from simulink? Because the model time varies a lot depending on the selected input parameters, it’s not possible to ‘predict’ simulation time.
Any ideas?
Thanks!
Nevermind..just found your other tutorial and read through their comments
I have the same problem with my standalone aplication that show an error, ”undifined function sim for param type char”.
Could you help me, please?
Thank you.
I am finding problems in simulation for wind power quality.
Also how to apply wavelet toolbox for the same.
Olivia, if it says ‘undefined function’ that probably means you don’t have simulink installed or the proper toolbox (costs extra $$) from TheMathWorks. I find the same issue with lots of cool statistics functions that I want to use but can’t.
hi,i want your help
i make a project about image proceesing
and iuse simulink with Display block to show threshold value and use GUI with Edit text to show value of Display block in it but u can not do that
so how i take the the value of the display block from simulink to display in edit text which called ‘threshold’ in GUI and this value changed due to the image
thanks alot
please send the solution to my e-mail
Hello,
thanks for the tutorial ^_^
I’m having the problem that the simulink model takes ages to simulate if i call it from my GUI. If i start within simulink the simulation is finished after ~2minutes.
I cancelled the simulation from the GUI after 20minutes. Does anyone know how to solve this problem or can give me a reason for it so i might figure out a work-around?
Thanks for your help!
btw sorry to hear about you guys discontinuing the blog, thanks for all your hard work!
Hello,
Your tutorials are very helpful, thanks a lot! I’m wondering if you could help me with something. I’m trying to run an external executable in my MATLAB GUI. The executable is actually a simple fingerprint scanner GUI. I would like to somehow run this GUI inside the one I created in MATLAB. Is this possible … ? I haven’t been able to find much help on it. Sorry, this isn’t related to Simulink, but hope you are able to help anyway! Thank you in advance
P.S. I know I can use open() to run the executable inside MATLAB, but I specifically want it to run inside the GUI.
i need help regarding QAM modulation using simulink and parameers are controlled fromGUI………..
can anyone help me to do this task..
I have the same problem as Olivia, even trying with the tutorial example I get the following output when pushing the simulate button:
Zane Montgomery, if the application runs in Matlab, this means that simulink and the necessary toolbox are installed. The problem seems to be that we need to specify something else in the deploytool configuration.
Any ideas/ suggestions?
Sorry J.M. but I don’t have Simulink access to play around with it.
I recommend bringing your issue to the MathWorks forums where they get much higher traffic for questions: http://www.mathworks.com/matlabcentral/
good luck!
Thanks for the tutorial! Well done!!
Is there any way to deploy the GUI with the integrated model using the deployment tool. I think i have to change the sim and simset commands? Need some help, pls.
Hello and thank you very much for your great tutorials.
My question is that if there is a way to debug a GUI (and a simulink model), like the same way we debug an .m file? I’d like to see what goes on in my workspace.
Regards,
Faezeh
Thank you very much for your great tutorial, it helps a lot
Is it possible to display simulink discrete time eye diagram and scatter plot scope output on matlab GUI . I have finished the simulink block for qpsk and it woks fine simulating using simulink but I don’t know who to display the output of discrete time eye diagram and constellation diagram on matlab GUI, can any one help me with this pls
hi,
can i ask if Matlab GUI can be linked to Code Composer Studio? Thanks
hi
hi to every’ mat-laber’ nice tutorials great work keep going.
i have created a simulink model contains a virtual reality ‘vr sink’ how can i call it from my GUI
hi,
I am a new user of Matlab, I create a GUI which link the SIMULINK model. However, it contains FIS file inside the SIMULINK model. I can set the parameter inside the SIMULINK, but there is problem for simulating since the FIS file cannot define inside the m-file of GUI, the error that come out is as followed:
“Error in ‘fuzzyblock3/south-east controller’: Parameter ‘control2′
cannot be evaluated. MATLAB error message: Error using ==> sim
Undefined function or variable ‘control2′.”
The fuzzyblock3 is the simulink model while the control2 is the FIS file.
Can any 1 help.
Thanks
Inside the program, some of the m-file in GUI is originally created. Therefore, I dun know where should I put this MATLAB code, and what should I insert inside.
Thank a lot
hi, does anyone know how to pass variable parameter from GUI to simulink in runtime?
in another word, if I have simulink model that run INF drawing some charts on a scope, and I need though a GUI sliding bar to keep passing the sliding bar value to simulink scope as I am changing the bar values, the smulink is running inf.
Any idea how to implement that?
hello, I had a problem and you solved it, thank you for your helpful tutorial.
Hello all,
I need help, i am a new user for gui, i have created a gui with two sliders and one axes, i created in such a way that, i used compass having 0 to 360 degree circle..
so if i use the left slider the pointer start moving from 0 to left , if i use the another slider it starts moving right…
My questions i need to show this gui in simulink… how can i interface to simulink
can any one please help…
if you need my files, i will send it to your email address, let me know your email ID
thanking you.
%%%%This is the gui call back function:
function varargout = x1(varargin)
% X1 M-file for x1.fig
% X1, by itself, creates a new X1 or raises the existing
% singleton*.
%
% H = X1 returns the handle to a new X1 or the handle to
% the existing singleton*.
%
% X1(’CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in X1.M with the given input arguments.
%
% X1(’Property’,'Value’,…) creates a new X1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before x1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to x1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE’s Tools menu. Choose “GUI allows only one
% instance to run (singleton)”.
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help x1
% Last Modified by GUIDE v2.5 24-Apr-2010 16:05:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(’gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @x1_OpeningFcn, …
‘gui_OutputFcn’, @x1_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
% End initialization code - DO NOT EDIT
% — Executes just before x1 is made visible.
function x1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to x1 (see VARARGIN)
% Choose default command line output for x1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes x1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% — Outputs from this function are returned to the command line.
function varargout = x1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% — Executes during object creation, after setting all properties.
function Figure_CreateFcn(hObject, eventdata, handles)
% hObject handle to Figure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate Figure
temp = handles.wdir;
handles.radius = [6 ];
%Convert the wind direction, given as angles, into radians before converting the wind direction into Cartesian coordinates.
handles.rdir = handles.wdir * pi/180;
[x,y] = pol2cart(handles.rdir,handles.radius);
compass(x,y);
guidata(hObject,handles);
% — Executes on slider movement.
function right_Callback(hObject, eventdata, handles)
% hObject handle to left (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
temp = get(hObject,’Value’);
%if ((temp > 0 ) && (temp 0 ) && (temp < 90))
% wdir = temp;
%end
handles.radius = [6 ];
handles.wdir = temp * 100;
handles.rdir = handles.wdir * pi/180;
[x,y] = pol2cart(handles.rdir,handles.radius);
compass(x,y);
guidata(hObject,handles);
% — Executes during object creation, after setting all properties.
function left_CreateFcn(hObject, eventdata, handles)
% hObject handle to left (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))
set(hObject,’BackgroundColor’,[.9 .9 .9]);
end
% — Executes on slider movement.
function left_Callback(hObject, eventdata, handles)
% hObject handle to left (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
% — Executes during object creation, after setting all properties.
function left_CreateFcn(hObject, eventdata, handles)
% hObject handle to left (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))
set(hObject,’BackgroundColor’,[.9 .9 .9]);
end
% — Executes on key press with focus on left and none of its controls.
function left_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to left (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% — Executes on slider movement.
function right_Callback(hObject, eventdata, handles)
% hObject handle to left (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
% — Executes during object creation, after setting all properties.
function right_CreateFcn(hObject, eventdata, handles)
% hObject handle to left (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))
set(hObject,’BackgroundColor’,[.9 .9 .9]);
end
iam posting the gui call back function here…
[...] Matlab GUI Tutorial – Integrating Simulink Model into a GUI from Blinkdagger.com. This one shows how to interface a Simulink Model with GUIDE using two techniques. [...]
hello sir,
I am sowmya… thnks for the tutorial on Gui, it is very easy to learn…i would like to know more on simulink. please let me know more details how to run or work in simulink..
Thanks & regards