MATLAB Answers

how to plot a continuous graph in a loop

63 views (last 30 days)
Sukhversha Luthra
Sukhversha Luthra on 29 Jan 2018
Commented: Sukhversha Luthra on 30 Jan 2018
for k=1:10;
x=5;
y=2*x-5*k*k*k
plot(k,y,'*');
hold on;
end
This program gives me a dotted graph.
however I wanted to get a regular(continuous) graph.
Please help me to find suitable command for that.

Answers (2)

Morteza Hajitabar Firuzjaei
you can make your vectors and plot your graph, like:
s = [1 1 1 1];
t = [2 4 5 3];
G = graph(s,t);
plot(G);
Mortrza Hajitabar Firuzjaei
  1 Comment
Sukhversha Luthra
Sukhversha Luthra on 30 Jan 2018
but I need to get a graph for a loop in which k is known but 'y', that depends on 'k', gets its values in the loop itself

Sign in to comment.


Star Strider
Star Strider on 29 Jan 2018
Try this:
kv = 1:10;
for k=1:length(kv)
x=5;
y(k) = 2*x-5*k*k*k;
end
figure
plot(kv, y)

Community Treasure Hunt

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

Start Hunting!