How to get a column vector for all the considered time instants?

2 views (last 30 days)
Hi everyone. I have a problem with this code. At the end I would like to obtain the r_ORF column vector for all the time instants (41) but I don't understand why this does not happen in this code. Thanks in advance.
clc;clear all; close all;
% Components determination in ORF
% ECI (GEOC) to ORF matrix determination
A = load('DatiCosmoSkymed.txt');
times = A(:,1);
for i = 1: length(times)
r_inertial(1,i)= A(i,8);
r_inertial(2,i)= A(i,9);
r_inertial(3,i)= A(i,10);
v_inertial(1,i)= A(i,11);
v_inertial(2,i)= A(i,12);
v_inertial(3,i)= A(i,13);
kORF_ECI=-r_inertial/norm(r_inertial);
jORF_ECI=-cross(r_inertial,v_inertial)/norm(cross(r_inertial,v_inertial));
iORF_ECI=cross(jORF_ECI,kORF_ECI);
M_ECItoORF(1,1)=iORF_ECI(1,1);
M_ECItoORF(1,2)=iORF_ECI(2,1);
M_ECItoORF(1,3)=iORF_ECI(3,1);
M_ECItoORF(2,1)=jORF_ECI(1,1);
M_ECItoORF(2,2)=jORF_ECI(2,1);
M_ECItoORF(2,3)=jORF_ECI(3,1);
M_ECItoORF(3,1)=kORF_ECI(1,1);
M_ECItoORF(3,2)=kORF_ECI(2,1);
M_ECItoORF(3,3)=kORF_ECI(3,1);
r_ECI = r_inertial;
r_ORF = M_ECItoORF*r_ECI;
display(r_ORF)
end

Accepted Answer

Walter Roberson
Walter Roberson on 11 Oct 2021
% Components determination in ORF
% ECI (GEOC) to ORF matrix determination
A = load('DatiCosmoSkymed.txt');
times = A(:,1);
num_times = size(times,1);
r_ORDF = cell(num_times,1);
for i = 1: num_times
r_inertial(1,i)= A(i,8);
r_inertial(2,i)= A(i,9);
r_inertial(3,i)= A(i,10);
v_inertial(1,i)= A(i,11);
v_inertial(2,i)= A(i,12);
v_inertial(3,i)= A(i,13);
kORF_ECI=-r_inertial/norm(r_inertial);
jORF_ECI=-cross(r_inertial,v_inertial)/norm(cross(r_inertial,v_inertial));
iORF_ECI=cross(jORF_ECI,kORF_ECI);
M_ECItoORF(1,1)=iORF_ECI(1,1);
M_ECItoORF(1,2)=iORF_ECI(2,1);
M_ECItoORF(1,3)=iORF_ECI(3,1);
M_ECItoORF(2,1)=jORF_ECI(1,1);
M_ECItoORF(2,2)=jORF_ECI(2,1);
M_ECItoORF(2,3)=jORF_ECI(3,1);
M_ECItoORF(3,1)=kORF_ECI(1,1);
M_ECItoORF(3,2)=kORF_ECI(2,1);
M_ECItoORF(3,3)=kORF_ECI(3,1);
r_ECI = r_inertial;
r_ORF{i} = M_ECItoORF*r_ECI;
end
I think you should reconsider your code a bit.
The first iteration, you write to the first column of r_inertial, so r_intertial is 3 x 1. M_ECItoORF is 3 x 3. In the calculation of r_ORF you use the * operator between the 3 x 3 M_ECItoORF and the 3 x 1 R_ECI to get a 3 x 1 result the first iteration.
The second iteration, you write to the second column of r_interial, so r_inertial is 3 x 2. And for kORF_ECI and jORF_ECI you use that entire 3 x 2 r_intertial . Are you certain that you want to be using the cumulative r_intertial in the calculation, not just the "current" column of r_intertial ?
Then you get down to the r_ORF, M_ECI is still 3 x 3, r_ECI is now 3 x 2 because it is is the 3 x 2 r_inertial, so r_ORF becomes 3 x 2, not 3 x 1.
And so on, until you get to the end, and the last r_ORF is 3 x number_of_times .
Does this make sense to do ???
  3 Comments
Loren99
Loren99 on 12 Oct 2021
At the end I would like to diplay on the command window r_ORF as 3x1 column vectors for each time instant analyzed
Walter Roberson
Walter Roberson on 12 Oct 2021
% Components determination in ORF
% ECI (GEOC) to ORF matrix determination
A = load('DatiCosmoSkymed.txt');
times = A(:,1);
num_times = size(times,1);
r_ORDF = zeros(3, num_times);
for i = 1: num_times
r_inertial(1,1)= A(i,8);
r_inertial(2,1)= A(i,9);
r_inertial(3,1)= A(i,10);
v_inertial(1,1)= A(i,11);
v_inertial(2,1)= A(i,12);
v_inertial(3,1)= A(i,13);
kORF_ECI=-r_inertial/norm(r_inertial);
jORF_ECI=-cross(r_inertial,v_inertial)/norm(cross(r_inertial,v_inertial));
iORF_ECI=cross(jORF_ECI,kORF_ECI);
M_ECItoORF(1,1)=iORF_ECI(1,1);
M_ECItoORF(1,2)=iORF_ECI(2,1);
M_ECItoORF(1,3)=iORF_ECI(3,1);
M_ECItoORF(2,1)=jORF_ECI(1,1);
M_ECItoORF(2,2)=jORF_ECI(2,1);
M_ECItoORF(2,3)=jORF_ECI(3,1);
M_ECItoORF(3,1)=kORF_ECI(1,1);
M_ECItoORF(3,2)=kORF_ECI(2,1);
M_ECItoORF(3,3)=kORF_ECI(3,1);
r_ECI = r_inertial;
r_ORF(:,i) = M_ECItoORF*r_ECI;
end
I believe that should give you a 3 x (number of times) array

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!