Pad a matrix with additional rows and concatenate another column
2 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Aref Majdara
2018 年 4 月 29 日
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 ?
3 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!