Write a function that will plot cos(x) for x values ranging from –pi to pi in steps of 0.1, using black *’s. It will do this three times across in one Figure Window, with varying line widths
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:12| Question number:18.12
All Answers
total answers (1)
cosLineWidths.m
function cosLineWidths(varargin)
% Plots cos(x) 3 times using subplot with
% varying line widths
% Format of call: cosLineWidths or cosLineWidths()
% or cosLineWidths(multiplier)
x = -pi: 0.1: pi;
y = cos(x);
multiplier = 1;
if nargin == 1
multiplier = varargin{1};
end
for i = 1:3
subplot(1,3,i)
plot(x,y,'k*','LineWidth', i*multiplier)
sptitle = sprintf('Line Width %d', i*multiplier);
title(sptitle)
xlabel('x')
ylabel('cos(x)')
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer