How to add a scalar to the first element in each row of an array?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mark Munson
el 23 de Ag. de 2022
Comentada: Mark Munson
el 24 de Ag. de 2022
I am trying to execute a code to convert an entire trajectory in the rotating frame back into an inertial frame. I am having syntax issues with my for loop. I can't figure out how to properly add the scalar MU_Earth_Moon to the first element in each row of the 1001 x 6 array, S. As isee it, the problem is either in: S(ii,:) = S(ii,:) + MU_Earth_Moon or the CR3BP_to_Inertial function.
----------------------------------------------------------------------------------------------------------------
S_end = S(end, :)'
%% Part-5: Convert the S/C trajectory back to Earth-centered Inertial frame.
S_sc = zeros(size(S, 1), 6);
for ii = 1:size(S, 1)
% Retrieve the state in CR3BP Rotating frame wrt the barycenter.
x = S(ii, :)';
% Shift the state to be Earth-centered.
S(ii,:) = S(ii,:) + MU_Earth_Moon;
% Convert the state from CR3BP Rotating to Inertial frame.
S_sc(ii,:) = CR3BP_to_Inertial(t, S(ii,:));
% Convert the Inertial state to dimensional units.
S_sc(ii, 1:3) = [ lstar*x(1) lstar*S(ii) lstar*S(ii) ];
S_sc(ii, 4:6) = [ vstar*S(ii) vstar*S(ii) vstar*S(ii) ];
end
-------------------------------------------------------------------------------------------------------------
function [S] = CR3BP_to_Inertial(t, s)
% Define rotation matrix from Rotating to Inertial.
A = [ cos(0) -sin(0) 0;
sin(0) cos(0) 0;
0 0 1];
B = [ -sin(0) -cos(0) 0;
cos(0) -sin(0) 0;
0 0 0];
R_rotating_inertial = [ A zeros(3,3);
B A];
% Perform the Inertial to Rotating transformation of the state.
S = R_rotating_inertial*s;
end
0 comentarios
Respuesta aceptada
KSSV
el 23 de Ag. de 2022
A = rand(5,6) ; % random data
[m,n] = size(A) ;
iwant = zeros(m,n+1) ;
iwant(:,2:end) = A ;
% Calculate the first element to append
for i = 1:5
iwant(i,1) = rand ;
end
iwant
Más respuestas (0)
Ver también
Categorías
Más información sobre Coordinate Transformations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!