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

concatenate vectorspad matrix rows

Hello, all!
I've included a sample of the code I'm using to pad a matrix with additional rows, then concatenate another column to that matrix. I can get the code to work for the first row of the matrix, but I'm not sure how to scale it for all six rows. I've tried using a for-loop but then get an error that the dimensions are not consistent.
mu = 398600.4415;
test_data = [6778.14 0 20 60 90 60; 6778.14 0 20 60 90 60; 7178.14 0 40 60 90 60; ...
7178.14 0 40 60 90 60; 7578.17 0 60 60 90 60; 7578.17 0 60 60 90 60];
% Calculate time in minutes
C = unique(test_data(:,1));
for i = 1:length(C)
if C(i) == 6778.14
T(i) = (sqrt((4*pi.^2)/(mu) * C(i).^3))/60;
elseif C(i) == 7178.14
T(i) = (sqrt((4*pi.^2)/(mu) * C(i).^3))/60;
else
T(i) = (sqrt((4*pi.^2)/(mu) * C(i).^3))/60;
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';
[m n] = size(T_step);
temp = padarray(test_data(1,:), [m-1 0], 'replicate','pre');
test_data = [temp, T_step(:,1)]
In the end, if the value in the first column of test_data is 6778.14, I need to concatenate the first column of T_step. Likewise the second column of T_step for 7178.14 and the third column for 7578.14.
I hope this is clear enough but if you need more detail, please let me know. I'd appreciate any help you can provide.

Best Answer

Hi Bill, I'm trying to understand your question. So, for this specific test data that you have provided, what are the dimensions of the matrix that you expect to get at the end? Is it 36x7 ?