Indices on the left side are not compatible with the size of the right side error

1 view (last 30 days)
So I'm writing code to create a matrix, M that stores various values for theta and x, but i'm unsure as to what to do about the error. Please let me know what I need to correct in order to overcome the error.
M=[];
theta=linspace(0,180,401);
x=linspace(0,10,501);
for i_theta = 1:length(theta)
for i_x = 1:length(x)
M(i_x,i_theta)= 1200*sind(theta(i_theta)) +400*cosd(theta)*x(i_x);
end
end
****************************************************************************
Unable to perform assignment because the indices on the left side are not compatible with the
size of the right side.
Error in Lab7 (line 9)
M(i_x,i_theta)= 1200*sind(theta(i_theta)) +400*cosd(theta)*x(i_x);

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 11 Mar 2019
It's a typo in this line
M(i_x,i_theta)= 1200*sind(theta(i_theta)) +400*cosd(theta)*x(i_x);
I think it should be
M(i_x,i_theta)= 1200*sind(theta(i_theta)) +400*cosd(theta(i_theta))*x(i_x);

More Answers (1)

Kevin Phung
Kevin Phung on 11 Mar 2019
M=[];
theta=linspace(0,180,401);
x=linspace(0,10,501);
for i_theta = 1:length(theta)
for i_x = 1:length(x)
M(i_x,i_theta)= 1200*sind(theta(i_theta)) +400*cosd(theta(i_theta))*x(i_x);
end
end
you were missing the indexing for cosd(theta)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!