
´ÙÀ½Àº MATLAB ÀÇ °£´ÜÇÑ ¼³¸í°ú ¼±Çü´ë¼ö¿¡¼ÀÇ ¿¹¸¦ ¼öÇаú ÀÌÁöÀº ¾çÀÌ Á¤¸®ÇÑ °ÍÀ» À̻󱸱³¼ö°¡ ¼öÁ¤ÇÑ °ÍÀÔ´Ï´Ù. ¼÷Á¦°¡ ÀÖÀ» ¿¹Á¤ÀÌ´Ï ¹Ì¸® ÀÍÇô µÎ±â ¹Ù¶ø´Ï´Ù..
¼º´ë ¼öÇаú À̻󱸱³¼ö
¢Â ¼±Çü´ë¼öÇаú MATLAB »ç¿ë¹ýÀÇ ¿¹ (I)
¢¡ MATLABÀº °·ÂÇÑ ¼öÇÐÀû ´É·ÂÀ» °®°í ÀÖ°í, ¶ÇÇÑ ½±°Ô ÁÖ¾îÁø »óȲÀ» ÄÚµùÈ ÇÒ ¼ö ÀÖ´Ù. ±× µ¿¾È À̻󱸱³¼ö´Ô²² Àü»ê¼öÇаú Çà·Ä·Ð °ÀǸ¦ µéÀ¸¸ç Mathematica³ª Hlinprac°ú °°Àº ¼öÇаü·Ã µµ±¸¸¦ µé¾î º¸°í ¶Ç °£´ÜÈ÷ ³ª¸¶ »ç¿ëÇØ º¸¾Ò´Âµ¥ MATLAB¸¸Å °·ÂÇÏÁö ¾Ê´Ù°í ÇÑ´Ù. ÇöÀç ¿Ü±¹ÀÇ ¿©·¯ ³ª¶ó¿¡¼µµ ¸ðµç ÄÚµùÀ» ´ëºÎºÐ MATLABÀ¸·Î ÀüȯÇÏ·Á´Â Ãß¼¼ÀÎ µí ÇÏ´Ù. ¿ì¸®³ª¶ó¿¡¼ ÇöÀç °³¹ß ÁßÀÎ "¼ÀÅø·Î(Cemtulro)"¶ó´Â ¼ÒÇÁÆ®¿þ¾îµµ MATLAB °ú °°Àº ±¸Á¶ÀÌ´Ù.
°ú°Å¿¡´Â FortranÀ¸·Î ÀÛ¼ºµÇ¾úÀ¸³ª, ÇöÀç´Â MathWorks»ç¿¡¼ C++·Î ÀÛ¼ºÇÏ¿´´Ù. ÀϹÝÀûÀ¸·Î MATLABÀÌ ÀÌ¿ëµÇ´Â ¹üÀ§´Â ¼öÇаú °ü·ÃµÈ °è»êÀ̳ª ¾Ë°í¸®Áò °³¹ß, »óȲ ¸ðµ¨¸µ°ú dataºÐ¼®, ¿©·¯ °¡Áö °úÇаú °øÇÐÀûÀÎ ±×·¡ÇÈ Ç¥Çö, Graphical User Interface¿¡ ÀÇÇÑ ¿¡Çø®ÄÉÀÌ¼Ç °³¹ßµîÀÌ´Ù.
ÇöÀç ¹öÀü 5.03ÀÌ ³ª¿ÍÀÖ´Â MATLABÀº ¿ÜºÎ ÇÁ·Î±×·¥, Áï C, Fortran°ú linkÇØ¼ ÀÌ¿ëÇÒ ¼ö ÀÖ´Â ±â´Éµµ Á¦°øÇϰí ÀÖ´Ù. PC»Ó¸¸ ¾Æ´Ï¶ó UNIX, MAC.¿¡¼µµ »ç¿ëÇÒ ¼ö ÀÖÀ¸¸ç ÀÌ¿ë ¹æ¹ýÀº °ÅÀÇ °°´Ù.
¢¡ InstallationÇϱâ À§ÇÑ ±âº» »ç¾ç
¡¤Intel 486 ÇÁ·Î¼¼¼ ÀÌ»ó (math coprocessorÆ÷ÇÔ, Pentium 133ÀÌ»ó ±ÇÀå)
¡¤RAM 16MB ÀÌ»ó
¡¤Help file¿¡´Â HTML¹®¼¿Í .PDF¹®¼°¡ Àִµ¥ .PDF¹®¼´Â www.adobe.com
¿¡ Á¢¼ÓÇÏ¿© ¾òÀ» ¼ö ÀÖ´Ù.
¼³Ä¡ ¹æ¹ýÀº ÀÚµ¿ ¼³Ä¡µÇ´Â ±âŸ ¼ÒÇÁÆ®¿þ¾î°ú µ¿ÀÏÇϹǷΠ»ý·«
¢Â MATLAB ½Ç½À
´ÙÀ½Àº ÀÎÅÍ³Ý http://www.math.utah.edu/lab/ms/matlab/matlab.html »çÀÌÆ®¿¡ ÀÖ´Â MATLAB¿¡ °üÇÑ ±âº»ÀûÀÎ »ç¿ë¹æ¹ý¿¡ °üÇÑ ¼³¸íÀ» Á¤¸®ÇÏ°í ½ÇÁ¦ ÇÁ·Î±×·¥¿¡¼ È®ÀÎÇÑ ³»¿ëÀÌ´Ù.
¡à%matlab ¡àa = [ 1 2; 2 1 ] a = 1 2 2 1 ¡àa^2 ans = 5 4 4 5 |
¢º Çà·ÄÀÇ ±âº»¿¬»ê
À§ÀÇ ¿¹¿¡¼ a¶ó´Â matrix¸¦ Á¤ÀÇÇÏ°í ±×°ÍÀÇ Çà·ÄÀÇ power(a^2)¸¦ °è»êÇÏ¿´´Ù.
ÇàÀÇ ¿ø¼Ò´Â ºóÄÀ̳ª (,)·Î ±¸ºÐÇÏ°í ¿ÀÇ ¿ø¼Ò´Â (;)À¸·Î ±¸ºÐÇÑ´Ù. ±×¸®°í [ ]À¸·Î ´Ý¾Æ ÁØ´Ù.
¡àclear all ¡àclc ¡àa=[1 2;3 4] a = 1 2 3 4 ¡àb=[1 2;0 1] b = 1 2 0 1 ¡àa*b ans = 1 4 3 10 ¡àb*a ans = 7 10 3 4
|
´ÙÀ½Àº Çà·Ä a¿Í b¸¦ Á¤ÀÇÇÏ°í ±âŸ ¿©·¯ °¡Áö Çà·Ä¿¬»êÀ» ÇØº¸¾Ò´Ù.
Çà·ÄÀÇ °ö a*b¿Í b*aÀÇ ±³È¯ÀÌ ¼º¸³ÇÏÁö ¾ÊÀ½À» º¼ ¼ö ÀÖ´Ù.
¡àa+b ans = 2 4 3 5 ¡às=a+b; ¡àinv(s) ans = -2.5000 2.0000 1.5000 -1.0000 ¡àeig(a) ans = -0.3723 5.3723 ¡àdet(s) ans = -2 |
inv(s)´Â Çà·ÄÀÇ ¿ªÇà·ÄÀ» ±¸ÇÑ´Ù.
eig(a)´Â Çà·ÄÀÇ °íÀ¯Ä¡¿Í °íÀ¯¹éÅ͸¦ ±¸ÇÑ´Ù.
det(s)´Â Çà·ÄÀÇ determinant¸¦ ±¸ÇÑ´Ù.
'clear all'Àº ¸ðµç º¯¼ö¿Í ÇÚµéÀÌ Áö¿ì°í 'clc' Àº DOS¿¡¼ 'cls'¿Í °°Àº ±â´ÉÀ¸·Î º¯¼ö¿Í Çڵ鿡´Â ¿µÇâÀÌ ¾øÀÌ È¸éÀ» Áö¿î´Ù.
¡àc=[1 2 3; 4 5 6; 7 8 9] c = 1 2 3 4 5 6 7 8 9 ¡àd=c' d = 1 4 7 2 5 8 3 6 9 ¡àtrace(d) ans = 15
|
Çà·ÄÀÇ transpose´Â (')À¸·Î ±¸Çϸç trace(d)´Â Çà·ÄÀÇ ´ë°¢ÇÕÀ» ±¸ÇÏ´Â ¿¬»êÀÌ´Ù.
¡àeye(3) ans = 1 0 0 0 1 0 0 0 1 ¡àpascal(3) ans = 1 1 1 1 2 3 1 3 6 ¡àmagic(4) ans = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
|
´ÙÀ½Àº ¿©·¯ °¡Áö Ư¼ö Çà·Ä ÇÔ¼öµéÀÇ ¿¹ÀÌ´Ù.
'eye(Â÷¼ö)'´Â ´ÜÀ§Çà·Ä(identity matrix)¸¦ ¸¸µé¾î ÁÖ´Â Çà·ÄÀ̸ç, 'pascal(3)Àº pascal ÀÇ »ï°¢ÇüÀ» ±¸ÇÏ´Â ÇÔ¼öÀ̰í 'magic'Àº Çà°ú ¿ ±×¸®°í ´ë°¢¼ººÐÀÇ ÇÕÀÌ ¸ðµÎ °°Àº Çà·ÄÀ» ¸¸µç´Ù.
¢º System of equations
´ÙÀ½ÀÇ linear equationÀ» °í·ÁÇØº¸ÀÚ

À̰ÍÀ»
Çà·Ä Ç¥ÇöÀ¸·Î AX=B ¶ó Çϰí A°¡ invertibleÇÏ´Ù°í ÇÒ ¶§ X=A-1B·Î ±¸Çϴµ¥ MATLAB¿¡¼´Â X=A\B·Î Ç¥ÇöÇÑ´Ù.
,
¶ó Çϰí ÇØ¸¦ ±¸Çϸé
¡àA=[2 3;5 7] A = 2 3 5 7 ¡àB=[1;0] B = 1 0 ¡àA£ÜB ans = -7.0000 5.0000
|
¢º Loops
°£´ÜÇÑ programingÀ» ÇØº¸ÀÚ.
¡àa=[.8 .1;.2 .0]; ¡àx=[1;0]; ¡àfor i=1:10, x=a*x, end x = 0.8000 0.2000 x = 0.6600 0.1600 x = 0.5440 0.1320 x = 0.4484 0.1088 x= 0.3696 0.0897
|
,
¶óÇϰí islandÀÇ Àα¸º¯È¿¡ µû¸¥ XÀÇ º¯È¸¦ °í·ÁÇØ º¸ÀÚ. 1ÇàÀÇ ¿ø¼Ò
1Àº island ¼ºÎ Áö¹æÀÇ Àα¸ºñÀ²À̰í 2ÇàÀÇ 0´Â µ¿ºÎÁö¿ªÀÇ Àα¸ºñÀ²À» ³ªÅ¸³½´Ù.
T´ÜÀ§ÀÇ ½Ã°£ÀÌ °æ°úÇÑ ÈÄ¿¡ Àα¸´Â y=aX·Î ÁÖ¾îÁø´Ù. ÀÌ ¶§ ¼ºÎÀÇ Àα¸Áß 0.8ÀÌ
¸Ó¹«¸¦ È®·üÀ̰í 0.2°¡ µ¿ºÎ·Î À̵¿ÇÒ È®·üÀÌ´Ù. ÇÑÆí µ¿ºÎÀÇ Àα¸´Â 0.9ÀÇÈ®·ü·Î
¸Ó¹«¸£°í ¼ºÎ·Î À̵¿ÇÒ È®·üÀº 0.1ÀÌ´Ù. µû¶ó¼ ´ÙÀ½°ú °£Àº MATLAB programing¿¡
ÀÇÇØ¼ ¿¬¼ÓÀûÀÎ Àα¸º¯ÈÀÇ ºñÀ²À» ¿¹»óÇÒ ¼ö ÀÖ´Ù.
x = 0.3046 0.0739 x = 0.2511 0.0609 x = 0.2070 0.0502 x = 0.1706 0.0414 x = 0.1406 0.0341 x = 0.1159 0.0281
|
ÀÌÇÏÀÇ Ãâ·Â³»¿ëÀº »ý·«ÇÔ
¢º Graphing
Function of one variable
y=sin(t)¸¦ interval t=0¿¡¼ t=10±îÁö ÇÏ¿© ±×·Áº¸ÀÚ
¡àt=0: .3: 10; ¡ày=sin(t); ¡ày2=cos(t); ¡àplot(t,y,'r',t,y2,'y') ¡à |
t = ÃʱⰪ :Áõ°¡ºÐ : ¸»±â°ª
plot(t,y)´Â 2Â÷¿ø ±×·¡ÇÁ¸¦ Ç¥ÇöÇÑ´Ù. À§ÀÇ °æ¿ì´Â sin(t)¿Í cos(t)ÀÇ ±×·¡ÇÁ¸¦ ÇÑ Â÷Æ®¿¡ ³ªÅ¸³»¾úÀ¸¸ç 'r'Àº red, 'y'´Â yellow·Î ¼±ÀÇ »ö±òÀ» ³ªÅ¸³½´Ù. °á°ú´Â ´ÙÀ½°ú °°´Ù.

Function of two variables
function z(x,y) = x exp(-x2 - y2)ÀÇ ±×·¡ÇÁ¸¦ ±×·Áº¸ÀÚ
óÀ½ commandÀÇ meshdomÀº -2<=x<=2, -2<=y<=2
¡à[x,y] = meshdom(-2:.2:2, -2:.2:2); ¡àz=x .* exp(-x.^2 -y.^2); ¡àmesh(z) ¡àset(gca,'xlim',[0 25],'ylim',[0 30],'zlim',[-0.5 0.5]) ¡à |
¸¦ ³ªÅ¸³»¸ç ±×·¡ÇÁÀÇ ÀÛÀº °ÝÀÚ¹«´Ì´Â 0.2ÀÇ ³ÐÀÌ¿Í 0.2 ³ôÀÌÀÌ´Ù. mesh´Â 3Â÷¿ø ±×·¡ÇÁ¸¦ ±×¸®´Â ÇÔ¼öÀ̰í xlim, ylim, zlimÀº °¢°¢ÀÇ ÁÂÇ¥Ãà¿¡ ´ëÇÑ °æ°è¸¦ ³ªÅ¸³½´Ù. °á°ú´Â ´ÙÀ½°ú °°´Ù.

¢ºM-file
MATLAB¾ð¾î·Î ¾²·ÁÁø ÆÄÀϵéÀ» ¸»Çϸç, ¿¬¼ÓÀûÀÎ MATLAB¹®ÀåµéÀ» ¼öÇàÇÏ´Â script mode¿Í ÀÔ·Â ¸Å°³º¯¼ö¿Í Ãú·Â ¸Å°³º¯¼ö¸¦ ´Ù·ç´Â function mode°¡ ÀÖ´Ù. M-file ´Â MATLABÀÌ Á¦°øÇÏ´Â text editor,¸¦ ÀÌ¿ëÇÏ¿© ÀÛ¼º ÇÒ ¼öÀÖ´Ù.
´ÙÀ½Àº °£´ÜÇÑ M-file ÀÛ¼ºÀ» ¿¹·Î µç °ÍÀÌ´Ù.
¢¡ n!À» ±¸ÇÏ´Â ÇÔ¼ö¸¦ M-file·Î ÀÛ¼ºÇÑ °ÍÀÌ´Ù. (function mode)
¸ÕÀú FileÀÇ New¿¡¼ M-fileÀ» Ŭ¸¯ÇÏ¿© text editor âÀ» ºÒ·¯ ¿Â´Ù.
±×¸®°í ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÑ´Ù.
function y=fact(n) %fact(n)ÇÔ¼ö´Â n¿¡ ´ëÇÑ factorial °ªÀ» ±¸ÇÑ´Ù. y=prod(1:n); |
function Ãâ·Â º¯¼ö = ÇÔ¼öÀ̸§(ÀԷº¯¼ö) ·Î ÇÔ¼ö¸¦ Á¤ÀÇÇϰí %¿¡´Â ÁÖ¼®À» ´Ü´Ù. prod´Â 1ºÎÅÍ n±îÁö ¿ø¼Òµé°£ÀÇ °öÀ» ³ªÅ¸³½´Ù.
ÀÛ¼ºÀÌ ¿Ï·áµÇ¸é ÇÔ¼öÀ̸§(fact.m)À¸·Î ÀúÀåÇÑ´Ù.
´ÙÀ½Àº fact.m ÇÔ¼ö¿¡ ÀÇÇØ¼ 5!À» °è»êÇØ º» °á°úÀÌ´Ù.
¡àinput_n=5; ¡ày=fact(input_n) y = 120 ¡à |
´ÙÀ½Àº M-fileÀ» ÀÌ¿ëÇÑ 3Â÷¿ø ±×·¡ÇÁÀÇ Ãâ·Â°úÁ¤ÀÌ´Ù.
title('smh graph') [x,y]=meshdom(-2:.2:2, -2:.2:3) z=x.*sin(-x.^2-y.^2)+y.*cos(-x.^2-y.^2)+tan(x)+tan(y) mesh(z) grid |
°á°ú´Â ´ÙÀ½°ú °°´Ù.
ÀÌ º¸°í¼´Â MATLABÀ» »ç¿ëÇÏ´Â Ãʺ¸ ¼³¸íÀ̱⠶§¹®¿¡ °£´ÜÇÑ ¼³¸í¸¸Çß°í, µ¶ÀÚÀûÀ¸·Î À¯¿ëÇÑ M-fileÀ» ÀÛ¼ºÇÏÁö´Â ¸øÇÑ ´ë½Å ÀÎÅÍ³Ý»ó¿¡ ¿Ã·ÁÁ® ÀÖ´Â À¯¿ëÇÑ M-file ÀڷḦ ´Ù¿î ¹Þ¾Æ³õ¾Ò´Ù.
©ç È£ÁÖÀÇ ¸ð³ª½¬´ëÇпø»ýÀÌ ¾î±ºÅ½»ç¸¦ À§ÇÑ ÃÊÀ½ÆÄŽ»çÀåºñ¸¦ MATLABÀ¸·Î ¸ðµ¨¸µÇϱâ À§ÇÑ M-file (MATLAB 4.2C¿ë)
function plcdemo(action);
%PLCDEMO Continuous planar Demo.
%
% Grant Hampson, Andrew Paplinski 16-1-95
% Monash University, Melbourne Australia.
% Information regarding the play status will be held in
% the axis user data according to the following table:
play= 1;
stop=-1;
global g1
if nargin<1,
action='initialize';
end;
if strcmp(action,'initialize'),
figNumber=figure( ...
'Name','Continuous Time Beamforming Using Planar Array', ...
'NumberTitle','off', ...
'Visible','off', ...
'BackingStore','off');
%===================================
% Information for all buttons
labelColor=[0.8 0.8 0.8];
top=.95;
bottom=0.05;
btnWid=0.15;
btnHt=0.1;
right=0.95;
left=right-btnWid;
% Spacing between the button and the next command's label
spacing=-0.042;
%====================================
% The CONSOLE frame
frmBorder=0.02;
yPos=bottom-frmBorder;
frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
h=uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.50 0.50 0.50]);
%====================================
% The first slider
btnNumber=1;
yPos=top-(btnNumber-1)*(btnHt+spacing);
callbackStr='plcdemo(''build'');';
% Generic button information
sldPos=[left yPos-1.5*btnHt btnWid btnHt];
labelPos1=[left yPos-btnHt/2 btnWid btnHt/2];
labelPos2=[left yPos-btnHt btnWid btnHt/2];
sld1Hndl=uicontrol( ...
'Style','slider', ...
'Units','normalized', ...
'Position',sldPos, ...
'Callback',callbackStr);
uicontrol( ...
'Style','text', ...
'String','Steering', ...
'Units','normalized', ...
'Position',labelPos1);
uicontrol( ...
'Style','text', ...
'String','Direction 1', ...
'Units','normalized', ...
'Position',labelPos2);
%====================================
% The second slider
btnNumber=4;
yPos=top-(btnNumber-1)*(btnHt+spacing);
callbackStr='plcdemo(''build'');';
% Generic button information
sldPos=[left yPos-1.5*btnHt btnWid btnHt];
labelPos1=[left yPos-btnHt/2 btnWid btnHt/2];
labelPos2=[left yPos-btnHt btnWid btnHt/2];
sld2Hndl=uicontrol( ...
'Style','slider', ...
'Units','normalized', ...
'Position',sldPos, ...
'Callback',callbackStr);
uicontrol( ...
'Style','text', ...
'String','Steering', ...
'Units','normalized', ...
'Position',labelPos1);
uicontrol( ...
'Style','text', ...
'String','Direction 2', ...
'Units','normalized', ...
'Position',labelPos2);
%====================================
% The third slider
btnNumber=7;
yPos=top-(btnNumber-1)*(btnHt+spacing);
callbackStr='plcdemo(''build'');';
% Generic button information
sldPos=[left yPos-1.5*btnHt btnWid btnHt];
labelPos1=[left yPos-btnHt/2 btnWid btnHt/2];
labelPos2=[left yPos-btnHt btnWid btnHt/2];
sld3Hndl=uicontrol( ...
'Style','slider', ...
'Units','normalized', ...
'Position',sldPos, ...
'Callback',callbackStr);
uicontrol( ...
'Style','text', ...
'String','Number of', ...
'Units','normalized', ...
'Position',labelPos1);
uicontrol( ...
'Style','text', ...
'String','Sensors', ...
'Units','normalized', ...
'Position',labelPos2);
%====================================
% The fourth slider
btnNumber=10;
yPos=top-(btnNumber-1)*(btnHt+spacing);
callbackStr='plcdemo(''build'');';
% Generic button information
sldPos=[left yPos-1.5*btnHt btnWid btnHt];
labelPos1=[left yPos-btnHt/2 btnWid btnHt/2];
labelPos2=[left yPos-btnHt btnWid btnHt/2];
sld4Hndl=uicontrol( ...
'Style','slider', ...
'Units','normalized', ...
'Position',sldPos, ...
'Callback',callbackStr);
uicontrol( ...
'Style','text', ...
'String','Sensor', ...
'Units','normalized', ...
'Position',labelPos1);
uicontrol( ...
'Style','text', ...
'String','Spacing', ...
'Units','normalized', ...
'Position',labelPos2);
%====================================
% The INFO button
labelStr='Info';
callbackStr='plcdemo(''info'')';
infoHndl=uicontrol( ...
'Style','push', ...
'Units','normalized', ...
'Position',[left bottom+btnHt+0.01 btnWid btnHt], ...
'String',labelStr, ...
'Callback',callbackStr);
%====================================
% The CLOSE button
labelStr='Close';
callbackStr='close(gcf)';
closeHndl=uicontrol( ...
'Style','push', ...
'Units','normalized', ...
'Position',[left bottom btnWid btnHt], ...
'String',labelStr, ...
'Callback',callbackStr);
% Uncover the figure
hndlList=[sld1Hndl sld2Hndl sld3Hndl sld4Hndl infoHndl closeHndl];
set(figNumber, ...
'Visible','on', ...
'UserData',hndlList);
% initialise sliders to about the right values
set(sld1Hndl,'Value',.5);
set(sld2Hndl,'Value',.5);
set(sld3Hndl,'Value',.4);
set(sld4Hndl,'Value',.3);
g1 = axes( 'Units','normalized','Position',[0.04 0.10 0.72 0.73]);
contpl(0,0,8,.003,g1);
elseif strcmp(action,'build'),
%====================================
% Use slider values and calculate new graphs
axHndl=gca;
figNumber=gcf;
hndlList=get(figNumber,'Userdata');
sld1Hndl=hndlList(1);
sld2Hndl=hndlList(2);
sld3Hndl=hndlList(3);
sld4Hndl=hndlList(4);
infoHndl=hndlList(5);
closeHndl=hndlList(6);
% ====== Start of Demo
% Get values from buttons
dir1=(-90+(180*get(sld1Hndl,'Value')))*pi/180;
dir2=(-90+(180*get(sld2Hndl,'Value')))*pi/180;
m=20*get(sld3Hndl,'Value');
d=0.001+.005*get(sld4Hndl,'Value');
contpl(dir1,dir2,m,d,g1);
% ====== End of Demo
elseif strcmp(action,'info');
end; % if strcmp(action, ...
©è ´ÙÀ½Àº MATLAB ftp site¿¡¼ ±¸ÇÑ °ÍÀε¥ figure window¿¡ ¿øÀ» Ãß°¡ÇϰíÀÚ ÇÒ ¶§ À¯¿ëÇÏ°Ô »ç¿ëÇÏ ¼ö ÀÖ´Â M-fileÀÇ ³»¿ëÀÌ´Ù.
function h=circle(r,x0,y0,C,Nb)
% CIRCLE adds circles to the current plot
%
% CIRCLE(r,x0,y0) adds a circle of radius r centered at point x0,y0.
% If r is a vector of length L and x0,y0 scalars, L circles with radii r
% are added at point x0,y0.
% If r is a scalar and x0,y0 vectors of length M, M circles are with the same
% radius r are added at the points x0,y0.
% If r, x0,y0 are vector of the same length L=M, M circles are added. (At each
% point one circle).
% if r is a vector of length L and x0,y0 vectors of length M~=L, L*M circles are
% added, at each point x0,y0, L circles of radius r.
%
% CIRCLE(r,x0,y0,C)
% adds circles of color C. C may be a string ('r','b',...) or the RGB value.
% If no color is specified, it makes automatic use of the colors specified by
% the axes ColorOrder property. For several circles C may be a vector.
%
% CIRCLE(r,x0,y0,C,Nb), Nb specifies the number of points used to draw the
% circle. The default value is 300. Nb may be used for each circle individually.
%
% h=CIRCLE(...) returns the handles to the circles.
%
% Try out the following (nice) examples:
%
%% Example 1
%
% clf;
% x=zeros(1,200);
% y=cos(linspace(0,1,200)*4*pi);
% rad=linspace(1,0,200);
% cmap=hot(50);
% circle(rad,x,y,[flipud(cmap);cmap]);
%
%% Example 2
%
% clf;
% the=linspace(0,pi,200);
% r=cos(5*the);
% circle(0.1,r.*sin(the),r.*cos(the),hsv(40));
%
%
%% Example 3
%
% clf
% [x,y]=meshdom(1:10,1:10);
% circle([0.5,0.3,0.1],x,y,['r';'y']);
%
%% Example 4
%
% clf
% circle(1:10,0,0,[],3:12);
%
%% Example 5
%
% clf;
% circle((1:10),[0,0,20,20],[0,20,20,0]);
% written by Peter Blattner, Institute of Microtechnology, University of
% Neuchatel, Switzerland, blattner@imt.unine.ch
% Check the number of input arguments
if nargin<1,
r=[];
end;
if nargin==2,
error('Not enough arguments');
end;
if nargin<3,
x0=[];
y0=[];
end;
if nargin<4,
C=[];
end
if nargin<5,
Nb=[];
end
% set up the default values
if isempty(r),r=1;end;
if isempty(x0),x0=0;end;
if isempty(y0),y0=0;end;
if isempty(Nb),Nb=300;end;
if isempty(C),C=get(gca,'colororder');end;
% work on the variable sizes
x0=x0(:);
y0=y0(:);
r=r(:);
Nb=Nb(:);
if isstr(C),C=C(:);end;
if length(x0)~=length(y0),
error('length(x0)~=length(y0)');
end;
% how many rings are plottet
if length(r)~=length(x0)
maxk=length(r)*length(x0);
else
maxk=length(r);
end;
% drawing loop
for k=1:maxk
if length(x0)==1
xpos=x0;
ypos=y0;
rad=r(k);
elseif length(r)==1
xpos=x0(k);
ypos=y0(k);
rad=r;
elseif length(x0)==length(r)
xpos=x0(k);
ypos=y0(k);
rad=r(k);
else
rad=r(fix((k-1)/size(x0,1))+1);
xpos=x0(rem(k-1,size(x0,1))+1);
ypos=y0(rem(k-1,size(y0,1))+1);
end;
the=linspace(0,2*pi,Nb(rem(k-1,size(Nb,1))+1,:)+1);
h(k)=line(rad*cos(the)+xpos,rad*sin(the)+ypos);
set(h(k),'color',C(rem(k-1,size(C,1))+1,:));
end;
¢Ñ ³» Çà·Ä·Ð °ÀǸ¦ µè´Â ´ëÇпø»ýÀº ÀÌ µÎ M-fileÀ» ½ÇÇàÇÏ¿© ¸ðµ¨¸µÇÏ¿© Á¦ÃâÇϱ⠹ٶø´Ï´Ù.
¢º¸¶Áö¸·À¸·Î MATLABÀ» °øºÎÇϱ⿡ À¯¿ëÇÑ »çÀÌÆ®µéÀ» Á¤¸®ÇÏ¿´´Ù.
http://www.indiana.edu/~statmath
http://www.loveangel.net/bbs/board/matlab.html
mailto:alfeld@math.utah.edu
http://www.mathworks.com/education/basics.shtml
http://www.mathworks.com/education
![]()
¨Ï 2000 Prof. S.G.Lee, Dept. of Math of SungKyunKwan University