leftimage for poohprod.ru

Examples: MATLAB programming - Script Files -

In this example, we are going to program the plotting of two concentric circles and mark the center point with a black square. We use polar coordinates in this case (for a variation).

We can open a new edit window and type the following program (script). As already mentioned, lines starting with a '%' sign are comments, and are ignored by MATLAB but are very useful to the viewer.

% The initial instructions clear the screen, all
% of the variables, and close any figure
clc; clear; close all

% CIRCLE - A script file to draw a pretty circle
% We first generate a 90-element vector to be used as an angle
angle = linspace(0, 2*pi, 90);

% Then, we create another 90-element vector containing only value 2
r2 = linspace(2, 2, 90);

% Next, we plot a red circle using the 'polar' function
polar(angle, r2, 'ro')
title('One more Circle')

% We avoid deletion of the figure
hold on

% Now, we create another 90-element vector for radius 1
r1 = linspace(1, 1, 90);
polar(angle, r1, 'bx')

% Finaly, we mark the center with a black square
polar(0, 0, 'ks')

We save the script and run it with the 'run' icon (within the Editor):

icon to run script

Or we can run it from the Command Window by typing the name of the script.

We now get the concentric circles:

matlab programming 2 fig.

From 'Matlab Programming' to home

From 'Matlab Programming' to 'Matlab Examples'



footer for matlab programming page

Related pages

for loop matrix matlabhow to draw a bell curvetau rcnodal analysis examplestaylor series of cos xbinomial probability distribution calculatoralgorithm for finding gcd of two numbersreflection coefficient smith chartpolynomial root finder calculatoreconomic depreciationhow to figure square feet from inchesinterpolation using matlabgui in matlab examplesascii char tableoctal numberingintegral calculatorswriting a program in matlabdecimal to binary conversion examplesbinary letter chartmatlab imagwhile loops matlabhow to calculate permutationnumerical integral matlabcalculate bmi imperialtaylor expansion sinecircuit nodal analysisintegrand calculatorconversion to binary numberssolids of revolutionbinary code converter to numberstrapezoidal rule problemsdefine time constant of rc circuitint to string matlabcharging and discharging a capacitor in an rc circuitplot circle in matlabexamples of resistorshow to loop in matlabexponential regression problemsunit impulse function examplescollatz problemexamples of trapezoidal rulescrap car value calculatorplot graph matlabhow to convert cartesian to polarmatlab piecewise functionmatlab fillconvert ascii coderandom number generator in matlabprime factorization programamoritization tabledemorgan's lawcosine infinite seriesexample of a periodic functionsolve linear equation matlaboctal number system conversioncalculating factorialssawtooth functionmatlab mesh examplerc circuit discharge equationsolving matrix in matlabmatlab 3d histogramtaylor series of cosinecircle in matlabmatlab animation examplematlab solve matrix equationeuclidean algorithm gcfmatlab finance tutorialradioactive half life calculatormatlab 3d surface plot examplehow to solve equations using matlabtaylor series of cos x