Pad a matrix with additional rows and concatenate another column
Show older comments
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 7776x7.
The code runs through without errors, but the resulting matrix is 7776x6. 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!
Accepted Answer
More Answers (1)
Yuvaraj Venkataswamy
on 3 May 2018
0 votes
Check this line,
temp = padarray(parameters(index,:), [m-1 1], 'replicate','pre');
1 Comment
Bill Symolon
on 3 May 2018
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!