0% found this document useful (0 votes)
79 views5 pages

Task Description: %spray of Lines/ Rays

This document describes a MATLAB task to generate different plots by creatively using MATLAB functions and varying code parameters. The objectives are to learn how to plot graphs in MATLAB, visualize code results graphically, and obtain various patterns by varying parameters. The approach is to import MATLAB code into an m-file, simulate it to generate plots and patterns of various dimensions, and vary parameters to develop desired plots. Various built-in functions like "zeros" will be used to generate patterns, and trigonometric functions will develop visualizations by varying parameters over a length of values.

Uploaded by

Sulman Shahzad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views5 pages

Task Description: %spray of Lines/ Rays

This document describes a MATLAB task to generate different plots by creatively using MATLAB functions and varying code parameters. The objectives are to learn how to plot graphs in MATLAB, visualize code results graphically, and obtain various patterns by varying parameters. The approach is to import MATLAB code into an m-file, simulate it to generate plots and patterns of various dimensions, and vary parameters to develop desired plots. Various built-in functions like "zeros" will be used to generate patterns, and trigonometric functions will develop visualizations by varying parameters over a length of values.

Uploaded by

Sulman Shahzad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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.

You might also like