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.
You’re not subscripting either‘x’ or‘y’. That’s important because‘x’ is negative and zero, so it can’t be used as indices. Also, the lengths of both vectors have to be the same.
Best Answer