MATLAB: Error using / Matrix dimensions must agree…

errorplot

Below is my script:
>> clf
>> hold on
>> axis([-1 1 -1 1])
>> x=-1:0.0001:1;
>> y=cos(1/x)
>> plot(x,y)
May I know why I keep getting this error:-
(Error using / Matrix dimensions must agree...)?

Best Answer

It should be like this: >> clf >> hold on >> axis([-1 1 -1 1]) >> x=-1:0.0001:1; >> y=cos(1./x) >> plot(x,y)
always use .* ./ (mul and div resp)for element by element operations. And use * / without "." for matrix operations.