MATLAB: I put the code in, but when the grapg shows there is nothing… I don’t know what im going wrong and it NEEDS to be a for loop

for loopplotting

for x=0:360
y= cosd(x)
end
plot(x,y)

Best Answer

You need to tweak your code just a bit:
x=0:360;
for k1 = 1:length(x)
y(k1) = cosd(x(k1));
end
plot(x,y)
You have to address every element of ‘x’ separately in each iteration of the loop, and store every value calculated in vector ‘y’. Use the same value of the index variable in each vector.