Pad a matrix with additional rows and concatenate another column

조회 수: 4(최근 30일)
Bill Symolon
Bill Symolon 2018년 5월 3일
댓글: Walter Roberson 2018년 5월 3일
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
T(z) = (sqrt((4*pi.^2)/(mu) * C(z).^3))/60; % Period
% 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;
% Add the time steps to the parameters matrix
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)];
if(index == 1)
M = temp;
M = [M; temp];
parameters = M;
Thanks again for any help you can provide!

채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 3일
Those comparisons on the parameter values will probably never be true.
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 5월 3일
I suggest you debug with
vals = [6778.14, 7178.14, 7575.14];
for K = 1 : length(vals)
[~, idx] = min( abs(parameters(:,1)-vals(K)) );
fprintf('%closest to %g is at index %d and is %g which is a difference of %g\n', vals(K), idx, parameters(idx,1), parameters(idx,1)-vals(K));

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy 2018년 5월 3일
Check this line,
temp = padarray(parameters(index,:), [m-1 1], 'replicate','pre');
  댓글 수: 1
Bill Symolon
Bill Symolon 2018년 5월 3일
My mistake. When I copied the code into the question field, I missed one line: [m n] = size(T_step);
I don't think the padarray function is the problem.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by