MATLAB: Going up from negative in for loop counter

counterplotting

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.

Best Answer

You can avoid using negative index
x=-10:10;
n=numel(x);
y=zeros(1,n) % Pre-allocate
for k=1:numel(x)
y(k)=-3*x(k)^2;
end
plot(x,y,'--o')