How to link all points on plot?

I have a small issue, how to link various nonlinear points within loop functions-for example y=0;
for k=1:10
y=k*2+k^3;
plot(y,k,'o-');
hold on;
end
hold off;
The Plot result is as follows. I want to connect all those points. I have little knowledge of interpolations (interp1).
is

 Accepted Answer

Don't put them in loop....calculate all y at once...
k=1:10 ;
y=k*2+k.^3;
plot(y,k,'o-');

2 Comments

If you want to use loop...See the code...and you can learn few things in looping.
k = 1:10 ;
N = length(k) ;
y = zeros(N,1) ;
k = zeros(N,1) ;
figure
hold on
for i = 1:length(k)
k(i) = i ;
y(i)=i*2+i^3;
plot(y(i),k(i),'o-');
end
plot(y,k,'b')
KALYAN ACHARJYA
KALYAN ACHARJYA on 2 Jun 2017
Edited: KALYAN ACHARJYA on 13 Mar 2019
My exact code is like this
for k=1:40 (k only for the number of iterations & must be used)
some operation
sp= output values in between 0 and 1
sn= output values in between 0 and 1
plot (sn,sp);
axis([0 1 0 1]);
hold on
end hold off;

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!