can't get my ploy function to plot all the vectors at once
Show older comments
built this function to plot x1st though x5th
function [ pk ] = myployplotter( n,x )
for k=1:n
pk=x.^k;
plot(x,pk)
end
end
but it only plots the 5th value, with k=1:n shouldn't it plot all 5 at once? If not how can I fix it?
Answers (2)
Geoff Hayes
on 30 Oct 2015
0 votes
Henry - you need to add a hold on statement to your code so that subsequent calls to plot do not delete the previous graphic.
MATLAB can be written much more efficiently without loops:
function M = myployplotter(n,x)
M = bsxfun(@power,x(:),1:n);
plot(M);
end
And tested:
myployplotter(4,[0,1,3,0,2,1,2])

%
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!