Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
When I go to run this code, it says that my A(i) in the second for loop cannot match up with the size of the right side. Can someone help me debug what is happening here and why they arent compatible.
Thank you!
R0 = [8598.311720315167; 5076.086378182427; 46.47171438826854];
y = 2016; % Year
m = 2; % Month of February
d = 20; % Day
h = 12; % Hour
min = 28; % Minute
s = 25; % Second
tmax = 24*3600; % Seconds
t = s:10:tmax; % Seconds
r_t = R0;
for i = 1:length(t)
d2000(i) = (367*y) - floor((7*(y + floor((m+9)/12)))/4) + floor((275*m)/9)...
+ ((h + (min/60) + ((s+t(i))/3600))/24) + d - 730531.5;
theta(i) = 280.46061837 + 360.98564736628*d2000(i);
end
for i = 1:length(t)
A(i) = [cos(theta(i)) sin(theta(i)) 0;...
-sin(theta(i)) cos(theta(i)) 0;...
0 0 1];
rECEF(i) = A(i)*r_t;
end
xx = rECEF(1,:);
yy = rECEF(2,:);
zz = rECEF(3,:);
a = 6378.137*10^3; % Meters --> Ellipsoidal Equatorial Radius
e = sqrt(0.00669437999); % Eccentricity of Ellipsoid
b = a*sqrt(1-e^2);
w = sqrt(xx^2 + yy^2);
l = e^2/2;
m = (w/a)^2;
n = ((1-e^2)*zz/b)^2;
i = -(2*l^2 + m + n)/2;
k = l^2*(l^2 - m - n);
q = (m + n - 4*l^2)^3/216 + m*n*l^2;
D = sqrt((2*q - m*n*l^2)*m*n*l^2);
beta = i/3 - (q+D)^(1/3) - (q-D)^(1/3);
t = sqrt(sqrt(beta^2-k) - (beta+i)/2) - sign(m-n)*sqrt((beta-i)/2);
w1 = w/(t+l);
z1 = (1-e^2)*zz/(t-l);
lat = atan(z1/((1-e^2)*w1));
long = 2*atan((w-xx)/yy);
alt = sign(t-1+l)*sqrt((w-w1)^2 + (zz-z1)^2);
figure()
plot(long,lat,'r*')
xlabel('Longitudinal')
ylabel('Latitudinal')
grid on
grid minor
0 Kommentare
Antworten (2)
MaryD
am 29 Mär. 2020
You're trying to asign 3x3 matrix to A(i) which is vector of size i.
try A(1:3,1:3,i)=[cos(theta(i)) sin(theta(i)) 0;...
-sin(theta(i)) cos(theta(i)) 0;...
0 0 1];
0 Kommentare
Adam Danz
am 29 Mär. 2020
Bearbeitet: Adam Danz
am 31 Mär. 2020
The transformation matrix produces a 3x3 matrix and you're attempting to store the 3x3 matrix into a single 1x1 space in A(i).
It doesn't look like you need to store each iteration of A so you could probably just store the output in "A" instead of "A(i)". However, when you multiply "A" with "rECEF" it will result in a 3x1 vector and you'll have the same error since you're storing that 3x1 vector in a 1x1 space "rECEF(i)".
I recommend the following
rECEF = nan(3, length(t)); %pre-allocate your loop variable
for i = 1:length(t)
A = [cos(theta(i)) sin(theta(i)) 0;...
-sin(theta(i)) cos(theta(i)) 0;...
0 0 1];
rECEF(:,i) = A*r_t; %Store the 3x1 values by column
end
xx = rECEF(1,:);
yy = rECEF(2,:);
zz = rECEF(3,:);
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!