Pad a matrix with additional rows and concatenate another column
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bill Symolon
am 29 Apr. 2018
Kommentiert: Bill Symolon
am 30 Apr. 2018
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 Kommentare
Akzeptierte Antwort
Aref Majdara
am 29 Apr. 2018
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!