Going up from negative in for loop counter
Show older comments
I'm trying to make this code
for x=-10:10;
y=-3*x^2;
end
plot(x,y)
Plot like this code
x=-10:10;
y=-3*x.^2;
plot(x,y,'--o')
I've tried
for x=-10:10
y(x)=-3*x.^2;
end
plot(x,y,'--o')
which doesn't work because I can't have the negative x numbers as y(x). I'm lost on how to fix this. Thank you.
Accepted Answer
More Answers (1)
Mahdi
on 11 Sep 2013
When you plot, you`re only plotting the last point because the variable y is inside the for loop (and is not a matrix). Other than what`s been suggested, the way that you can do it is
for x=-10:10;
y=-3*x^2;
plot(x,y)
hold on
end
1 Comment
Mahdi
on 11 Sep 2013
Please note that you should avoid for-loops to plot things like this because they`ll be resource-consuming.
Categories
Find more on Just for fun in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!