Basic Matlab Ang Gui
Basic Matlab Ang Gui
I-1
Basic Matlab
Matrix definition
a=[1,2 ; 3,4] =>
a= 1 2
34
Vector is a matrix with one column or one row.
a=[1;2;3;4;5 ;; ] one column
b=[1,2,3,4,5,6 ,,..] one row
I-2
Basic Matlab
Example
a=[1,2,3,4,5];
b=[a;a;a]
Example
a=[1;2;3;4;5];
b=[a,a,a]
b=
b=
12345
12345
12345
Example (transpose)
a=[1;2;3;4;5];
b=a
b= 1 2 3 4 5
1111
2222
3333
4444
5555
Basic Matlab
Strings
a=[a,b,c]
a= abc
Strings
a=[a,b,c]
a= abc
Strings
a=[a,b,c]
b=[a,c,c]
b=[a;a;a]
b=[a,a,a]
c=(a==b);
b=
b=
c= 1 0 1
abc
abc
abc
abcabcabc
I-3
I-4
Basic Matlab
1 2
A
3 4
5 6
B
7 8
6 8
A B
10 12
19 22
A* B
43
50
5 12
A. * B
21
32
1 4
A. ^ 2
9 16
sin(1) sin(2)
sin( A)
sin(3) sin(4)
I-5
Basic Matlab
A=zeros(a1, a2, a3, an);
A is an n dimensional matrix of zeros.
A=ones(a1, a2, a3, an);
A is an n dimensional matrix of ones.
size(A) return the size of A at each diminution.
size(A,Dim) return the size of A at the diminution Dim.
Basic Matlab
A(m,n) returns the value of the matrix in row-m
and column-n.
b=A(1:end,1)
I-6
Basic Matlab
Functions in Matlab
function [output variables]=function_name (input variables)
I-7
I-8
Basic Matlab
Functions in Matlab
function [out_1,out_2,out_3] = Function_Dec (in_1,in_2,in_3)
out_1=in_1+in_2+in_3;
out_2=[ 'hello' ; 'world' ];
out_3=[1,2,3,4,5];
return;
I-9
Basic Matlab
Functions in Matlab
input:
[a,b,c]=Function_dec(5,3,2)
input:
[a,b,c]=Function_dec([1,2,3],[6,5,4],[3,4,5])
output:
a = 10
b = hello
world
output:
a = 10 11 12
b=
hello
world
c=
c=1
Basic Matlab
Bit-wise operations
(a,b)
(a,b)
(a,b)
(a,bit-num)
(a,bit-num,1/0)
(a,+/- shift_size)
Bit-wise AND.
Bit-wise OR.
Bit-wise XOR.
Get bit.
Set bit.
Bit-wise shift.
I - 10
Basic Matlab
conditions
If ( Boolean expression)
.
end;
Boolean expression
== : Is Equal
~=: Not Equal
> : Is grater then
< : Is less Then
>=: Is grater then or equal to
<=: Is less then or equal to
I - 11
Basic Matlab
conditions
switch switch_expr
case case_expr,
statement, ..., statement
case {case_expr1, case_expr2, case_expr3,...}
statement, ..., statement
...
otherwise,
statement, ..., statement
end
I - 12
I - 13
Basic Matlab
Loops
for j=start:step:end
.
end;
example:
for j=-1:0.2:3
.
end;
Basic Matlab
Drawing
yellow
magenta
cyan
red
green
blue
white
black
.
o
x
+
*
s
d
v
^
<
>
p
h
point
circle
x-mark
plus
star
square
diamond
triangle (down)
triangle (up)
triangle (left)
triangle (right)
pentagram
hexagram
- solid
: dotted
-. dashdot
-- dashed
I - 14
Basic Matlab
Drawing
Drawing a circle
t=0:0.1:2*pi;
x=10*cos(t);
y=10*sin(t);
plot (x,y);
x=10*cos(t);
y=10*sin(t);
plot (x,y,.);
I - 15
I - 16
Basic Matlab
Drawing
ezplot(x^2+y^2=1);
ezplot(x^2/5+y^2/20=1);
Basic Matlab
Drawing
a=0:0.2:2*pi;
b=ones(1,length(a));
c=sin(a'*b);
figure;
subplot(1,2,1);
surf(c);
I - 17
Basic Matlab
Drawing
figure;
t=0:0.1:2*pi+0.1;
b=ones(1,length(t));
z=b'*(1:1:length(t));
x=(10*sin(z)+15).*sin(t'*b);
y=(10*sin(z)+15).*cos(t'*b);
surf(x,y,z);
I - 18
I - 19
Basic Matlab
Some useful commands
figure
drawnow
hold on
Basic Matlab
Adding a path to a library
1
I - 20
I - 21
Basic Matlab
Adding a path to a library
9
10
I - 22
GUIs
Oren Meirom
Omikron Delta
I - 24
What is a Callback?
I - 26
I - 27
Push/Toggle Buttons
The push button is widely prevalent uicontrol
style that is used primarily to indicate that a
desired action should immediately take place.
The toggle button look just like push button,
except there is no intermediate state.Rather, the
button will remain in its selected or not selected
state after the user clicks on it.
>>mcpush
Check Box
Useful for representing two states of an option
that you may want to provide (usually as on and
off).
In its off state the check box will consist of an
empty or unfilled square. In the on state, the
check boxs square will contain a V sign.
>>mccheckbox,mccheckbox1
I - 28
I - 29
Radio Button
Similar to the check box in that there are two
states associated with each other.
Usually two or more radio buttons are linked
together as a group.They are linked in the sense
that only one of the buttons will be in its selected
state.
>>mcradiox
I - 30
Editable Text
Used in situations that require the user to enter
strings or characters or numbers. The strings , in
turn, are used by the application for which the
interface has been built.
Clicking anywhere within this object will change
the mouse from a pointer to a text insertion
indicator.
>>mcedit, mceditf
I - 31
List Boxes
New style provided by MATLAB 5.x
Very similar to pop-up menus.
>>mccheckboxwith a list box is that you
The main difference
can make the set of options visible to the user at
all times.
>>mclistbox
I - 32
Pop-up Menus
Used in situations where multiple choices need to
be available to the user.
When the user clicks and holds the mouse button
anywhere within the object, a list of choices
appear.
>>mcpopup
I - 33
Sliders
Useful in representing a fixed range of values
from which to choose.
The slider has no way of explicitly indicating the
numeric value that the slider represents.
Therefor, it is recommended that an editable text
or static text style uicontrol accompany the
slider.
>>mcslider, mcslider2
I - 34
Frames
Provide a solid background that helps blend a set
of uicontrols into one complete and cohesive
interface.
Used as an effective method of organizing the
GUI in a logical and intuitive fashion.
Static Text
Available for creating labels, status messages or
other information pertinent to the user.
Static text does not perform any action if the user
clicks on any part of the object. In addition , the
user can not edit the information that is displayed.
I - 35
I - 36
WindowButtonUpFcn- When clicking the mouse button up within the figure boundaries.
WindowButtonMotionFcn- When the mouse pointer moves within the figure boundaries.
KeyboardFcn- When the figure is active.
CreatFcn- When creating an object.
DeleteFcn- When deleting an object.
ResizeFcn- When resizing the figure.
I - 37
Object_H=GCBO
I - 38
Setting figure.
h0 = figure('Color',[0.8 0.8 0.8], ...
'Units','Normal', ...
'Position',[0.3 0.3 0.3 0.3], ...
'Tag','Fig1');
%Setting figure name
set(h0,'Name','Check and radio');
I - 39
set(h1,'ForegroundColor',[0.0,.0,0.0]);
%setting the background color
set(h1,'BackgroundColor',[0.0,1.0,0.0]);
I - 40