Convert a table vector of 31 by 13 elements to matrix of 13 by 31.

3 views (last 30 days)
Tunde Adubi
Tunde Adubi on 31 Mar 2022
Commented: Akira Agata on 3 Apr 2022
In the attached table, convert the 403 by 2 elements to a matrix of 13 by 31 or to 31 by 13 elements.
Every 13 rows contain the same variables. Each of these 13 rows could be called a PRN. Hence, there are 31 PRNs with 13 variables each.

Accepted Answer

Akira Agata
Akira Agata on 1 Apr 2022
Edited: Akira Agata on 3 Apr 2022
How about the following solution?
% Read data file
L = readlines('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/948584/Satellite_Data.txt');
% Extract data lines
L = regexp(L,'.+:\s*[+-\d\.E]+','match');
idx = cellfun(@isempty, L);
L(idx) = [];
L = string(L);
% Split each line by ':'
L = split(L,':');
% Extract data value and reshape
val = str2double(L(:,2));
val = reshape(val,13,[])';
% Extract valiable names
varNames = unique(L(:,1),'stable'); % [2022/4/3 update]
% Arrange as a table variable
T = array2table(val,'VariableNames',varNames);
% Show the result
disp(T)
ID Health Eccentricity Time of Applicability(s) Orbital Inclination(rad) Rate of Right Ascen(r/s) SQRT(A) (m 1/2) Right Ascen at Week(rad) Argument of Perigee(rad) Mean Anom(rad) Af0(s) Af1(s/s) week __ ______ ____________ ________________________ ________________________ ________________________ ________________ ________________________ ________________________ ______________ ___________ ___________ ____ 1 0 0.011557 5.0381e+05 0.9873 -7.566e-09 5153.6 -2.4142 0.88429 0.0019733 0.00040627 -7.276e-12 153 2 0 0.020595 5.0381e+05 0.96561 -7.7375e-09 5153.6 -2.5041 -1.4314 0.13692 -0.00065231 0 153 3 0 0.0039506 5.0381e+05 0.97255 -8.2289e-09 5153.6 -1.3792 0.94546 -1.1355 -0.00016975 -1.819e-11 153 4 0 0.0017419 5.0381e+05 0.96155 -7.8632e-09 5153.6 -0.29763 -3.0139 1.7449 -0.00018311 3.638e-12 153 5 0 0.005877 5.0381e+05 0.95955 -8.3546e-09 5153.6 -1.4201 1.0074 2.6606 -7.534e-05 0 153 6 0 0.0026941 5.0381e+05 0.98667 -7.6003e-09 5153.6 -2.4224 -0.91437 0.28653 0.00023556 1.4552e-11 153 7 0 0.015703 5.0381e+05 0.9512 -7.8975e-09 5153.6 0.72055 -2.2847 -0.67291 0.00031662 0 153 8 0 0.0074039 5.0381e+05 0.96452 -7.8632e-09 5153.7 2.7892 0.13281 2.2272 -6.0081e-05 0 153 9 0 0.0021639 5.0381e+05 0.95452 -7.9775e-09 5153.6 -0.35082 1.8765 2.6413 -0.00034904 3.638e-12 153 10 0 0.0075426 5.0381e+05 0.97237 -8.2175e-09 5153.6 -1.382 -2.4987 -2.0443 -0.00035095 -1.0914e-11 153 11 63 0.00027657 5.0381e+05 0.9624 -7.8518e-09 5153.7 -2.3712 2.77 2.2 -5.9128e-05 1.0914e-11 153 12 0 0.0087357 5.0381e+05 0.96959 -8.2289e-09 5153.5 1.8338 1.2597 -1.3104 -0.00018692 -7.276e-12 153 13 0 0.005826 5.0381e+05 0.96904 -7.7146e-09 5153.6 -0.19753 0.9429 1.714 0.00027943 7.276e-12 153 14 0 0.0015674 5.0381e+05 0.95299 -8.4118e-09 5153.6 1.8019 3.0283 -1.2548 -9.5367e-05 -3.638e-12 153 15 0 0.013964 5.0381e+05 0.93031 -8.2632e-09 5153.7 -0.45767 1.0801 1.253 -7.534e-05 3.638e-12 153 16 0 0.0128 5.0381e+05 0.96952 -8.2403e-09 5153.6 1.8524 0.7182 3.1167 -0.00048256 -3.638e-12 153 17 0 0.013502 5.0381e+05 0.97972 -7.6689e-09 5153.7 2.8715 -1.4932 2.1492 0.00058937 3.638e-12 153 18 0 0.0021372 5.0381e+05 0.97109 -7.7603e-09 5153.6 -2.4068 3.0851 0.23987 0.00021648 -7.276e-12 153 19 0 0.0090508 5.0381e+05 0.97853 -7.6346e-09 5153.6 2.9164 2.0207 -1.7112 0.00013256 3.638e-12 153 20 0 0.0050387 5.0381e+05 0.9418 -8.5146e-09 5153.7 -1.5347 -3.1293 0.98205 0.00051594 0 153 21 0 0.024556 5.0381e+05 0.95987 -7.726e-09 5153.5 -2.5059 -0.9834 2.3655 0.00015926 0 153 22 0 0.013092 5.0381e+05 0.96172 -7.7946e-09 5153.6 -0.24931 -1.8658 2.0497 0.00022984 7.276e-12 153 23 0 0.0020094 5.0381e+05 0.96742 -8.2746e-09 5153.6 -1.407 2.9934 -0.74647 -7.6294e-06 -3.638e-12 153 24 0 0.01238 5.0381e+05 0.93474 -8.0232e-09 5153.6 0.63729 0.81078 0.29557 0.00026703 -3.638e-12 153 25 0 0.010566 5.0381e+05 0.95704 -8.3775e-09 5153.6 1.7566 0.99089 -1.5868 0.00030041 3.638e-12 153 26 0 0.0069246 5.0381e+05 0.93789 -8.5718e-09 5153.6 1.709 0.38277 -2.2427 0.00019169 3.638e-12 153 27 0 0.010418 5.0381e+05 0.97324 -7.7489e-09 5153.6 2.8089 0.65342 2.2149 0.00015831 1.0914e-11 153 29 0 0.0019422 5.0381e+05 0.98176 -7.6575e-09 5153.7 2.8846 2.2323 2.3571 -0.00049305 -3.638e-12 153 30 0 0.0056334 5.0381e+05 0.93634 -8.0803e-09 5153.5 0.7332 -2.7275 -0.61893 -0.00051975 -3.638e-12 153 31 0 0.010443 5.0381e+05 0.9554 -7.8975e-09 5153.7 0.73876 0.3815 -1.1273 -0.00016975 0 153 32 0 0.0057702 5.0381e+05 0.95837 -7.8975e-09 5153.5 -0.33949 -2.3183 2.8448 -8.7738e-05 -7.276e-12 153
  2 Comments
Akira Agata
Akira Agata on 3 Apr 2022
Oh, I made a small mistake!
I have just added 'stable' option to the unique function to keep the variable name order in my previous answer. Thank you for pointing it out.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by