MATLAB: Pad a matrix with additional rows and concatenate another column

concatenate vectorspad matrix rows

Hello, all.
I asked this question a couple of days ago and you provided some excellent help. I've taken your code and scaled it up to my full data set, but it's still not working quite right. The goal is to end up with a matrix that is 7776×7.
The code runs through without errors, but the resulting matrix is 7776×6. The 7th column (time) isn't being concatenated properly. I hoping you can tell me what I'm missing. Here is my full code.
if true
% Define initial conditions
mu = 398600.4415;
Alt = 400:400:1200;
Ree = 6378;
a = Alt + Ree;
e = 1.7E-16;
i = 20:20:60;
RAAN = 0:60:300;
omega = 0:60:180;
nu = 0:60:300;
% Calculate the orbital period in minutes
C = unique(a);
for z = 1:length(C)
if C(z) == 6778.14
T(z) = (sqrt((4*pi.^2)/(mu) * C(z).^3))/60; % Period


elseif C(z) == 7178.14
T(z) = (sqrt((4*pi.^2)/(mu) * C(z).^3))/60; % Period
else
T(z) = (sqrt((4*pi.^2)/(mu) * C(z).^3))/60; % Period
end
end
% Divide the orbital period into 6 equal time steps
T_step = zeros(length(T), 6);
T_step(1,:) = [0:T(1)/5:T(1)];
T_step(2,:) = [0:T(2)/5:T(2)];
T_step(3,:) = [0:T(3)/5:T(3)];
T_step = T_step';
% Nested for-loops
index = 1;
for j = 1:length(a)
for k = 1:length(i)
for l = 1:length(RAAN)
for o = 1:length(omega)
for p = 1:length(nu)
parameters(index,:) = [a(j) e i(k) RAAN(l) omega(o) nu(p)];
index = index + 1;
end
end
end
end
end
% Add the time steps to the parameters matrix
R=length(parameters);
for index=1:R
temp = padarray(parameters(index,:), [m-1 0], 'replicate','pre');
if parameters(index,1) == 6778.14
temp = [temp, T_step(:,1)];
elseif parameters(index,1) == 7178.14
temp = [temp, T_step(:,2)];
elseif parameters(index,1) == 7578.17
temp = [temp, T_step(:,3)];
end
if(index == 1)
M = temp;
else
M = [M; temp];
end
end
parameters = M;
end
Thanks again for any help you can provide!

Best Answer

Those comparisons on the parameter values will probably never be true.