Sie sind auf Seite 1von 5

Task Description

Using MATLAB function creatively for generating different plots.

Learning Objectives

 Plotting graphs in MATLAB

 Visualizing code results graphically

 Varying parameters of code and obtaining various patterns

Approach

The MATLAB code shall be imported in the m-file and simulated. It will generate the plots and

patterns of various dimensions. The parameters shall be varied accordingly in order to develop

the desired plot.

Program Description

The program will use the various built in MATLAB functions like zeros in order to generate

various patterns. It will also use different trigonometric functions and develop the visualization

of parameters varied over a length of values.

Source Code

%Spray of lines/ rays


x=[50:-1:0];
y=[0:50];
x(1:2:end)=zeros();
y(1:2:end)=zeros();
plot(x,y);
% same spray of lines, but trying to curve it asymptotically
x=[0.01:0.01:2];
y=1./x;
x(1:2:end)=zeros();
y(1:2:end)=zeros();
plot(x,y);
x=[60:-1:0];
y=[0:60];

% create one set of arrays based in lower


% left corner, ie, around [0,0]
x(1:2:end)=zeros();
y(2:2:end)=zeros();

% Now draw one around the upper right.


% easy: just change the zeros to 50s!
x2=x;
y2=y;
x2(1:2:end)=60;
y2(2:2:end)=60;

plot(x,y,'g',x2,y2,'r');
% create a basic array of points in a circle
angle=[0:0.05:2*pi];
radius=40;
x=cos(angle)*radius;
y=sin(angle)*radius;

% make some copies, pulling out different offsets


x1=x(1:3:end);
y1=y(1:3:end);
x2=x(2:3:end);
y2=y(2:3:end)
x3=x(3:3:end);
y3=y(3:3:end);
% zero every other one to draw rays
x1(1:2:end)=zeros();
y1(1:2:end)=zeros();
x2(2:2:end)=zeros();
y2(2:2:end)=zeros();
x3(3:2:end)=zeros();
y3(3:2:end)=zeros();
plot(x1,y1,'rp-',x2,y2,'b*-',x3,y3,'g^-');
incr=0.08; % how many radians to shift each line
numlines=(pi/incr); % number of lines based on the increment.
angle=[0:incr+pi:pi*numlines]; % each new point is shifted by 180 degrees +
incr
radius=40;
x=cos(angle)*radius;
y=sin(angle)*radius;
%split into three arrays of alternating points to vary colors
x1=x(1:3:end);
y1=y(1:3:end);
x2=x(2:3:end);n
y2=y(2:3:end);
x3=x(3:3:end);
y3=y(3:3:end);
plot(x1,y1,'r*-',x2,y2,'bp-',x3,y3,'g^-');

%Doodle 6
t = 0:0.02:2*pi;
r = abs(sin(t).*cos(t));
figure
polarplot(t, abs(sin(2*t).*cos(2*t)))
title('abs(sin(t)*cos(t))')

Results
60

50

40

30

20

10

0
0 10 20 30 40 50 60
Conclusion

This lab helped me in getting hands on practice of generating useful MATLAB plots. Using the

code listed provided me a chance of generating plots and improvising adjustments in code. In

this way I was able to learn more about MATLAB plotting power.

Das könnte Ihnen auch gefallen