Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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);

Risposta accettata

Alex Mcaulley
Alex Mcaulley il 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);

Più risposte (1)

Kevin Phung
Kevin Phung il 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)

Categorie

Scopri di più su Language Fundamentals in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by