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

1 回表示 (過去 30 日間)
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);

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 3 月 11 日
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);

その他の回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 3 月 11 日
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)

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by