How to build

Layout Editor

Components

Example 1-clickme

Example 2 Factorial

  1. Add PB edit text and static text controls
  2. Change their properties: fontsize, font weight, string, tag, background color…..

(inactive, string, tag- look at code before and after change tags)

  1. Activate (compile) ----- get myfactorial.fig and myfactorial.m and run version of the factorial ------does not do anything so far.
  2. Add code needed

Example 3 -MyCalculator

Example 4 myplot - can write a user function for plotting

5-Money Convert

% --- Executes on selection change in lstFrom.

function lstFrom_Callback(hObject, eventdata, handles)

% hObject handle to lstFrom (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns lstFrom contents % % as cell array

% contents{get(hObject,'Value')} returns selected item from lstFrom

set(handles.edInput,'string','0.00');

set(handles.edOutput,'string','0.00');

function slEx_Callback(hObject, eventdata, handles)

% hObject handle to slEx (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

n=get(hObject,'value');

set(handles.txtEx,'string',n);

function edInput_Callback(hObject, eventdata, handles)

% hObject handle to edInput (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 edInput as text

% str2double(get(hObject,'String')) returns contents of edInput as a double

exchR=str2double(get(handles.txtEx,'string'));

minput=str2double(get(hObject,'string'));

set(handles.edOutput,'string',exchR*minput);

6-Guessing Game

% --- Executes on button press in pbNew.

function pbNew_Callback(hObject, eventdata, handles)

% hObject handle to pbNew (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

%%%tic

g=timerfind; stop(g); delete(g);

t1=timer;

h=handles.text1;

k=30+1;

set(handles.edTry,'string',0);

set(t1,'TimerFcn',@(x,y) set(h,'string',k-get(t1,'TasksExecuted')), ...

'Period', 1,'ExecutionMode','FixedSpacing','TasksToExecute',k);

start(t1)

set(hObject,'Enable','off');

RN=round(99*rand+1);

handles.t1=t1;

handles.RN=RN;

handles.fn=1;

guidata(hObject, handles);

function edTry_Callback(hObject, eventdata, handles)

% hObject handle to edTry (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 edTry as text

% str2double(get(hObject,'String')) returns contents of edTry as a uble

RN=handles.RN;

GN=str2num(get(hObject,'string'));

if handles.fn <=6 & str2num(get(handles.text1,'string'))> 0

if GN>RN

msgbox('Try a smaller number!');

elseif GN<RN

msgbox('Try a larger number!');

else

msgbox('You Win...... !');

set(handles.pbNew,'Enable','on');

end

handles.fn=handles.fn+1;

guidata(hObject, handles);

else

if str2num(get(handles.text1,'string'))==0

msgbox('Time is Over...... ');

set(handles.pbNew,'Enable','on');

else

msgbox('Exceeded 5 trials..');

set(handles.pbNew,'Enable','on');

stop(handles.t1);

end

end

Example 7- 3D plot

% --- Executes just before Graph3D is made visible.

function Graph3D_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 Graph3D (see VARARGIN)

% Choose default command line output for Graph3D

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes Graph3D wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% prepare data

handles.peaks=peaks(35);

handles.membrane=membrane;

[X,Y]=meshgrid(-8:0.5:8);

r=sqrt(X.^2+Y.^2)+eps;

sinc=sin(r)./r;

handles.sinc=sinc;

% current plot

handles.current_data=handles.peaks;

surf(handles.current_data);

guidata(hObject, handles);

% --- Executes on selection change in pmData.

function pmData_Callback(hObject, eventdata, handles)

% hObject handle to pmData (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pmData contents as cell array

% contents{get(hObject,'Value')} returns selected item from pmData

s=get(hObject,'string');

v=get(hObject,'value');

switch s{v}

case'Peaks'

handles.current_data=handles.peaks;

case'Membrane'

handles.current_data=handles.membrane;

case'Sinc'

handles.current_data=handles.sinc;

end

guidata(hObject, handles);

% --- Executes on button press in pbSurf.

function pbSurf_Callback(hObject, eventdata, handles)

% hObject handle to pbSurf (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

surf(handles.current_data);

% --- Executes on button press in pbMesh.

function pbMesh_Callback(hObject, eventdata, handles)

% hObject handle to pbMesh (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

mesh(handles.current_data);

% --- Executes on button press in pbCont.

function pbCont_Callback(hObject, eventdata, handles)

% hObject handle to pbCont (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

contour(handles.current_data);

Standalone Application Project

It may be needed to setup the MATLAB compiler by entering mbuild –setup and following steps in the command window).

> deploytool (enter at command window)

Enter name of project and then "OK"

Add *.m file as Main file; and*.fig file as shared resources

Then enter build, get

When done, get

Then click Close

Exit Matlab and go to "distrib" folder, and run Myfactorial.exe

Another way

From File menu Export GUI of myplot.fig into myplot-export.m

> deploytool at command window

Change name of project and location then OK, get

Add file you exported; the click Build

And

Then click Close

Exit Matlab and go to "distrib folder"

1