read part of a .txt file

2 visualizaciones (últimos 30 días)
Alberto Acri
Alberto Acri el 20 de Ag. de 2024
Comentada: Voss el 20 de Ag. de 2024
I have the attached .txt file. I would like to read only the lines where the number from 1 to 200 is included.
Each row should be divided into 7 columns: iter | continuity | x-velocity | y-velocity | z-velocity | time | iter.

Respuesta aceptada

Voss
Voss el 20 de Ag. de 2024
filename = 'file.txt';
str = readlines(filename);
C = arrayfun(@(s)sscanf(s,'%f %f %f %f %f %d:%d:%d %f'),str,'UniformOutput',false);
C(cellfun(@isempty,C)) = [];
M = [C{:}].';
time = duration(M(:,6:8));
M(:,6:8) = [];
names = strsplit(str(1),{' ','/'});
names(strcmp(names,"")) = [];
names{end} = [names{end} '_remaining'];
T = array2table(M,'VariableNames',names([1:end-2 end]));
T = addvars(T,time,'After',names{end-2})
T = 200x7 table
iter continuity x-velocity y-velocity z-velocity time iter_remaining ____ __________ __________ __________ __________ ________ ______________ 1 1 0.031087 0.05887 0.23416 00:39:48 199 2 0.43061 0.067927 0.12479 0.54336 00:35:38 198 3 0.18418 0.03545 0.05073 0.17127 00:32:18 197 4 0.17966 0.040429 0.058652 0.23452 00:29:38 196 5 0.16793 0.073768 0.090026 0.30663 00:26:11 195 6 0.13914 0.060295 0.069152 0.21426 00:24:05 194 7 0.14278 0.030375 0.034038 0.10929 00:23:01 193 8 0.099285 0.015474 0.018109 0.059613 00:21:31 192 9 0.079912 0.0078596 0.0095243 0.03249 00:20:19 191 10 0.052335 0.0051009 0.0060121 0.02016 00:19:20 190 11 0.039113 0.0027787 0.0033443 0.011593 00:19:10 189 12 0.026734 0.0024569 0.0028624 0.0092901 00:19:01 188 13 0.018456 0.0018653 0.002251 0.0067603 00:18:15 187 14 0.013085 0.0013615 0.0016217 0.0050884 00:18:14 186 15 0.0092158 0.00099823 0.0011905 0.0038379 00:16:59 185 16 0.0065331 0.00072516 0.00085892 0.0028239 00:16:35 184

Más respuestas (1)

Voss
Voss el 20 de Ag. de 2024
filename = 'file.txt';
T = readtable(filename,'CommentStyle','R','NumHeaderLines',0,'VariableNamingRule','preserve');
T(all(isnan(T{:,:}),2),:) = [];
T.Properties.VariableNames([6 7]) = {'time','iter_remaining'};
disp(T)
iter continuity x-velocity y-velocity z-velocity time iter_remaining ____ __________ __________ __________ __________ ________ ______________ 1 1 0.031087 0.05887 0.23416 00:39:48 199 2 0.43061 0.067927 0.12479 0.54336 00:35:38 198 3 0.18418 0.03545 0.05073 0.17127 00:32:18 197 4 0.17966 0.040429 0.058652 0.23452 00:29:38 196 5 0.16793 0.073768 0.090026 0.30663 00:26:11 195 6 0.13914 0.060295 0.069152 0.21426 00:24:05 194 7 0.14278 0.030375 0.034038 0.10929 00:23:01 193 8 0.099285 0.015474 0.018109 0.059613 00:21:31 192 9 0.079912 0.0078596 0.0095243 0.03249 00:20:19 191 10 0.052335 0.0051009 0.0060121 0.02016 00:19:20 190 11 0.039113 0.0027787 0.0033443 0.011593 00:19:10 189 12 0.026734 0.0024569 0.0028624 0.0092901 00:19:01 188 13 0.018456 0.0018653 0.002251 0.0067603 00:18:15 187 14 0.013085 0.0013615 0.0016217 0.0050884 00:18:14 186 15 0.0092158 0.00099823 0.0011905 0.0038379 00:16:59 185 16 0.0065331 0.00072516 0.00085892 0.0028239 00:16:35 184 17 0.0046371 0.00051631 0.00061075 0.0020341 00:16:51 183 18 0.0032128 0.00037676 0.00044936 0.0014998 00:15:50 182 19 0.0021458 0.00026463 0.00032018 0.0010666 00:16:13 181 20 0.0014188 0.00019936 0.00024452 0.0007886 00:15:54 180 21 0.00097407 0.00015474 0.00019254 0.00059831 00:15:38 179 22 0.00069554 0.00012646 0.00015869 0.00046624 00:15:24 178 23 0.00052069 0.00010429 0.00013118 0.00036589 00:15:12 177 24 0.00040411 8.7449e-05 0.00011026 0.0002938 00:15:02 176 25 0.00032564 7.6454e-05 9.6124e-05 0.00024236 00:14:52 175 26 0.00027088 6.7773e-05 8.4617e-05 0.00020239 00:14:44 174 27 0.00023079 6.0455e-05 7.5079e-05 0.00017043 00:14:36 173 28 0.00020185 5.5188e-05 6.7724e-05 0.00014498 00:14:29 172 29 0.00018225 5.189e-05 6.2583e-05 0.00012465 00:14:22 171 30 0.00016592 4.8861e-05 5.7741e-05 0.00010726 00:14:15 170 31 0.00015375 4.5861e-05 5.3322e-05 9.3153e-05 00:13:36 169 32 0.00014387 4.3362e-05 4.9977e-05 8.1007e-05 00:14:10 168 33 0.00013838 4.2538e-05 4.7716e-05 7.1491e-05 00:14:03 167 34 0.00013096 3.9989e-05 4.4447e-05 6.3107e-05 00:13:56 166 35 0.00012686 3.9223e-05 4.2906e-05 5.6236e-05 00:13:50 165 36 0.00012462 3.9436e-05 4.2323e-05 5.1158e-05 00:13:44 164 37 0.00011856 3.6437e-05 3.9055e-05 4.5568e-05 00:13:38 163 38 0.00011404 3.3787e-05 3.5785e-05 4.0604e-05 00:13:33 162 39 0.00011546 3.559e-05 3.7148e-05 3.8433e-05 00:13:27 161 40 0.00011323 3.5275e-05 3.6669e-05 3.5497e-05 00:13:22 160 41 0.00010896 3.3148e-05 3.422e-05 3.2485e-05 00:13:16 159 42 0.00010623 3.0292e-05 3.1121e-05 2.9157e-05 00:13:11 158 43 0.00010607 2.9316e-05 3.0326e-05 2.724e-05 00:13:06 157 44 9.7147e-05 2.3153e-05 2.392e-05 2.2227e-05 00:13:01 156 45 9.5748e-05 2.1038e-05 2.1335e-05 1.9527e-05 00:12:56 155 46 9.3478e-05 1.739e-05 1.7616e-05 1.6232e-05 00:13:21 154 47 9.3567e-05 1.621e-05 1.6625e-05 1.4684e-05 00:12:39 153 48 9.1671e-05 1.3723e-05 1.4092e-05 1.2574e-05 00:12:35 152 49 9.2228e-05 1.3645e-05 1.3824e-05 1.1935e-05 00:12:01 151 50 9.1441e-05 1.2725e-05 1.2891e-05 1.101e-05 00:12:03 150 51 9.2009e-05 1.4642e-05 1.4828e-05 1.2302e-05 00:11:04 149 52 9.0639e-05 1.3259e-05 1.3562e-05 1.1119e-05 00:11:16 148 53 8.9613e-05 1.0761e-05 1.1014e-05 9.0444e-06 00:10:25 147 54 8.9522e-05 8.9647e-06 9.2721e-06 7.5669e-06 00:10:43 146 55 8.9665e-05 8.1047e-06 8.3243e-06 6.7538e-06 00:10:27 145 56 8.9717e-05 7.7056e-06 7.9034e-06 6.2958e-06 00:10:13 144 57 8.9974e-05 7.9733e-06 8.0891e-06 6.3307e-06 00:10:01 143 58 9.2301e-05 1.4558e-05 1.4726e-05 1.1364e-05 00:09:51 142 59 8.9937e-05 1.2781e-05 1.3097e-05 9.9636e-06 00:09:43 141 60 8.8979e-05 1.0173e-05 1.0353e-05 7.9879e-06 00:09:35 140 61 8.8953e-05 8.4066e-06 8.5385e-06 6.5718e-06 00:09:56 139 62 8.9209e-05 7.6248e-06 7.7266e-06 5.8666e-06 00:09:43 138 63 8.9685e-05 7.9899e-06 8.042e-06 6.0322e-06 00:09:33 137 64 8.9484e-05 7.9082e-06 7.9398e-06 5.9536e-06 00:09:24 136 65 8.9191e-05 7.3696e-06 7.4418e-06 5.5597e-06 00:09:16 135 66 8.9196e-05 7.1435e-06 7.2106e-06 5.3476e-06 00:09:08 134 67 8.9155e-05 6.9211e-06 7.0093e-06 5.185e-06 00:09:02 133 68 8.9179e-05 6.9261e-06 6.9964e-06 5.1957e-06 00:08:56 132 69 8.9037e-05 6.6792e-06 6.7507e-06 4.9911e-06 00:08:50 131 70 8.8991e-05 6.4918e-06 6.5411e-06 4.8146e-06 00:08:45 130 71 8.8955e-05 6.3037e-06 6.3645e-06 4.6689e-06 00:08:40 129 72 8.8968e-05 6.2536e-06 6.31e-06 4.6026e-06 00:08:35 128 73 8.8907e-05 6.1375e-06 6.1925e-06 4.497e-06 00:08:30 127 74 8.8935e-05 6.0501e-06 6.1093e-06 4.4071e-06 00:08:26 126 75 8.8892e-05 6.0662e-06 6.0925e-06 4.3972e-06 00:08:22 125 76 8.8897e-05 6.0758e-06 6.0993e-06 4.4299e-06 00:08:42 124 77 8.893e-05 6.1981e-06 6.2266e-06 4.5347e-06 00:08:33 123 78 8.8891e-05 6.3053e-06 6.3293e-06 4.5962e-06 00:08:24 122 79 8.8818e-05 6.1953e-06 6.2373e-06 4.5181e-06 00:08:17 121 80 8.8858e-05 6.1763e-06 6.2168e-06 4.4893e-06 00:08:10 120 81 8.8865e-05 6.0515e-06 6.0841e-06 4.3822e-06 00:08:04 119 82 8.8874e-05 5.9964e-06 6.0286e-06 4.3356e-06 00:07:58 118 83 8.8867e-05 5.9183e-06 5.9639e-06 4.2834e-06 00:08:17 117 84 8.8844e-05 5.8322e-06 5.8723e-06 4.2091e-06 00:07:43 116 85 8.8829e-05 5.7852e-06 5.8254e-06 4.1701e-06 00:08:03 115 86 8.8851e-05 5.7673e-06 5.8177e-06 4.1566e-06 00:07:31 114 87 8.8834e-05 5.729e-06 5.784e-06 4.1267e-06 00:07:51 113 88 8.8836e-05 5.7338e-06 5.7801e-06 4.1259e-06 00:07:20 112 89 8.8821e-05 5.707e-06 5.7518e-06 4.1052e-06 00:07:40 111 90 8.8863e-05 5.8281e-06 5.8768e-06 4.197e-06 00:07:33 110 91 8.8865e-05 5.9441e-06 5.9967e-06 4.3031e-06 00:07:04 109 92 8.8834e-05 5.918e-06 5.9766e-06 4.2828e-06 00:07:24 108 93 8.882e-05 5.9228e-06 5.975e-06 4.2865e-06 00:07:18 107 94 8.8781e-05 5.8104e-06 5.8587e-06 4.1909e-06 00:07:12 106 95 8.8778e-05 5.7422e-06 5.7904e-06 4.1398e-06 00:07:06 105 96 8.8776e-05 5.6983e-06 5.7456e-06 4.1005e-06 00:07:01 104 97 8.8786e-05 5.6703e-06 5.7204e-06 4.0746e-06 00:06:56 103 98 8.8793e-05 5.6629e-06 5.7185e-06 4.0703e-06 00:07:11 102 99 8.8796e-05 5.6682e-06 5.7236e-06 4.0725e-06 00:06:42 101 100 8.8795e-05 5.6597e-06 5.7153e-06 4.0663e-06 00:06:59 100 101 8.8792e-05 5.6526e-06 5.707e-06 4.06e-06 00:06:31 99 102 8.8793e-05 5.6474e-06 5.7011e-06 4.0565e-06 00:06:28 98 103 8.8793e-05 5.6442e-06 5.6977e-06 4.054e-06 00:06:44 97 104 8.8794e-05 5.6427e-06 5.6965e-06 4.0527e-06 00:06:37 96 105 8.8793e-05 5.6435e-06 5.6965e-06 4.0528e-06 00:06:30 95 106 8.8793e-05 5.6429e-06 5.6961e-06 4.0524e-06 00:06:24 94 107 8.8792e-05 5.6423e-06 5.6957e-06 4.0514e-06 00:06:18 93 108 8.8795e-05 5.642e-06 5.6956e-06 4.0514e-06 00:06:13 92 109 8.8793e-05 5.6422e-06 5.6962e-06 4.0518e-06 00:06:08 91 110 8.8795e-05 5.6418e-06 5.6956e-06 4.0515e-06 00:06:03 90 111 8.8793e-05 5.6418e-06 5.6954e-06 4.0518e-06 00:06:16 89 112 8.8796e-05 5.6415e-06 5.6952e-06 4.0506e-06 00:05:50 88 113 8.8794e-05 5.6421e-06 5.6956e-06 4.0517e-06 00:05:47 87 114 8.8795e-05 5.6425e-06 5.6961e-06 4.0518e-06 00:06:00 86 115 8.8794e-05 5.6426e-06 5.6959e-06 4.0515e-06 00:05:36 85 116 8.8796e-05 5.6419e-06 5.6953e-06 4.0511e-06 00:05:50 84 117 8.8795e-05 5.6418e-06 5.6951e-06 4.0513e-06 00:05:43 83 118 8.8795e-05 5.6416e-06 5.695e-06 4.0508e-06 00:05:36 82 119 8.8794e-05 5.6417e-06 5.6952e-06 4.0511e-06 00:05:31 81 120 8.8795e-05 5.6423e-06 5.6955e-06 4.0516e-06 00:05:25 80 121 8.8794e-05 5.6419e-06 5.6955e-06 4.0516e-06 00:05:20 79 122 8.8796e-05 5.6417e-06 5.6952e-06 4.051e-06 00:05:15 78 123 8.8795e-05 5.6417e-06 5.6952e-06 4.0507e-06 00:05:11 77 124 8.8797e-05 5.6415e-06 5.6952e-06 4.0511e-06 00:05:06 76 125 8.8795e-05 5.6417e-06 5.6951e-06 4.0508e-06 00:05:02 75 126 8.8797e-05 5.6415e-06 5.6951e-06 4.0512e-06 00:05:12 74 127 8.8794e-05 5.6417e-06 5.6952e-06 4.0509e-06 00:05:05 73 128 8.8796e-05 5.6416e-06 5.695e-06 4.0512e-06 00:04:58 72 129 8.8795e-05 5.6417e-06 5.6951e-06 4.0514e-06 00:04:52 71 130 8.8796e-05 5.6416e-06 5.6951e-06 4.0499e-06 00:04:46 70 131 8.8795e-05 5.6416e-06 5.6952e-06 4.051e-06 00:04:41 69 132 8.8795e-05 5.6415e-06 5.6951e-06 4.0507e-06 00:04:36 68 133 8.8795e-05 5.6417e-06 5.6951e-06 4.0508e-06 00:04:31 67 134 8.8796e-05 5.6416e-06 5.6951e-06 4.0509e-06 00:04:26 66 135 8.8795e-05 5.6416e-06 5.6951e-06 4.0506e-06 00:04:22 65 136 8.8795e-05 5.6416e-06 5.6951e-06 4.0509e-06 00:04:17 64 137 8.8796e-05 5.6416e-06 5.6952e-06 4.051e-06 00:04:13 63 138 8.8795e-05 5.6415e-06 5.6952e-06 4.0511e-06 00:04:09 62 139 8.8794e-05 5.6416e-06 5.6951e-06 4.0506e-06 00:04:05 61 140 8.8796e-05 5.6414e-06 5.6951e-06 4.0516e-06 00:04:01 60 141 8.8795e-05 5.6416e-06 5.6952e-06 4.0511e-06 00:03:56 59 142 8.8796e-05 5.6415e-06 5.6951e-06 4.0504e-06 00:04:04 58 143 8.8794e-05 5.6416e-06 5.6952e-06 4.0506e-06 00:03:57 57 144 8.8796e-05 5.6415e-06 5.6951e-06 4.0509e-06 00:03:51 56 145 8.8795e-05 5.6416e-06 5.6951e-06 4.051e-06 00:03:46 55 146 8.8796e-05 5.6415e-06 5.6951e-06 4.0509e-06 00:03:41 54 147 8.8795e-05 5.6416e-06 5.6952e-06 4.0503e-06 00:03:36 53 148 8.8795e-05 5.642e-06 5.6956e-06 4.0513e-06 00:03:31 52 149 8.8794e-05 5.6418e-06 5.6953e-06 4.0515e-06 00:03:26 51 150 8.8795e-05 5.6415e-06 5.6951e-06 4.0512e-06 00:03:22 50 151 8.8794e-05 5.6417e-06 5.6951e-06 4.0511e-06 00:03:17 49 152 8.8795e-05 5.6415e-06 5.6949e-06 4.0513e-06 00:03:13 48 153 8.8794e-05 5.6416e-06 5.6951e-06 4.0508e-06 00:03:09 47 154 8.8795e-05 5.6415e-06 5.6949e-06 4.0506e-06 00:03:05 46 155 8.8794e-05 5.6416e-06 5.695e-06 4.0517e-06 00:03:01 45 156 8.8796e-05 5.6415e-06 5.695e-06 4.0509e-06 00:02:56 44 157 8.8793e-05 5.6416e-06 5.6951e-06 4.0506e-06 00:02:52 43 158 8.8795e-05 5.6415e-06 5.695e-06 4.0509e-06 00:02:57 42 159 8.8794e-05 5.6416e-06 5.695e-06 4.0511e-06 00:02:51 41 160 8.8795e-05 5.6415e-06 5.6951e-06 4.0505e-06 00:02:45 40 161 8.8794e-05 5.6416e-06 5.6951e-06 4.0512e-06 00:02:40 39 162 8.8795e-05 5.6416e-06 5.6951e-06 4.0511e-06 00:02:35 38 163 8.8794e-05 5.6417e-06 5.6951e-06 4.051e-06 00:02:30 37 164 8.8795e-05 5.6415e-06 5.6949e-06 4.0509e-06 00:02:26 36 165 8.8794e-05 5.6416e-06 5.695e-06 4.0505e-06 00:02:22 35 166 8.8795e-05 5.6414e-06 5.695e-06 4.0506e-06 00:02:17 34 167 8.8794e-05 5.6417e-06 5.695e-06 4.0516e-06 00:02:13 33 168 8.8795e-05 5.6414e-06 5.695e-06 4.0502e-06 00:02:09 32 169 8.8794e-05 5.6416e-06 5.695e-06 4.0509e-06 00:02:05 31 170 8.8795e-05 5.6415e-06 5.695e-06 4.0503e-06 00:02:00 30 171 8.8794e-05 5.6415e-06 5.6951e-06 4.0508e-06 00:01:56 29 172 8.8795e-05 5.6415e-06 5.6951e-06 4.051e-06 00:01:52 28 173 8.8794e-05 5.6416e-06 5.6951e-06 4.0513e-06 00:01:48 27 174 8.8794e-05 5.6415e-06 5.6951e-06 4.0506e-06 00:01:49 26 175 8.8793e-05 5.6416e-06 5.6951e-06 4.0506e-06 00:01:44 25 176 8.8795e-05 5.6415e-06 5.6951e-06 4.0512e-06 00:01:39 24 177 8.8793e-05 5.6416e-06 5.6952e-06 4.0508e-06 00:01:34 23 178 8.8795e-05 5.6415e-06 5.6951e-06 4.0514e-06 00:01:30 22 179 8.8793e-05 5.6416e-06 5.695e-06 4.0511e-06 00:01:25 21 180 8.8795e-05 5.6415e-06 5.695e-06 4.0509e-06 00:01:21 20 181 8.8793e-05 5.6416e-06 5.695e-06 4.0499e-06 00:01:17 19 182 8.8795e-05 5.6415e-06 5.695e-06 4.0507e-06 00:01:13 18 183 8.8793e-05 5.6415e-06 5.6951e-06 4.0506e-06 00:01:08 17 184 8.8795e-05 5.6415e-06 5.695e-06 4.0508e-06 00:01:04 16 185 8.8794e-05 5.6416e-06 5.6951e-06 4.0512e-06 00:01:00 15 186 8.8795e-05 5.6416e-06 5.695e-06 4.0514e-06 00:00:59 14 187 8.8794e-05 5.6416e-06 5.695e-06 4.0511e-06 00:00:52 13 188 8.8796e-05 5.6415e-06 5.695e-06 4.05e-06 00:00:50 12 189 8.8794e-05 5.6415e-06 5.695e-06 4.051e-06 00:00:46 11 190 8.8795e-05 5.6415e-06 5.695e-06 4.0507e-06 00:00:41 10 191 8.8795e-05 5.6415e-06 5.695e-06 4.0506e-06 00:00:39 9 192 8.8795e-05 5.6415e-06 5.6951e-06 4.0509e-06 00:00:32 8 193 8.8794e-05 5.6415e-06 5.695e-06 4.051e-06 00:00:30 7 194 8.8795e-05 5.6415e-06 5.6949e-06 4.0508e-06 00:00:24 6 195 8.8793e-05 5.6416e-06 5.695e-06 4.0507e-06 00:00:21 5 196 8.8795e-05 5.6415e-06 5.6951e-06 4.0505e-06 00:00:17 4 197 8.8794e-05 5.6416e-06 5.6951e-06 4.0505e-06 00:00:12 3 198 8.8794e-05 5.6414e-06 5.6951e-06 4.0509e-06 00:00:08 2 199 8.8793e-05 5.6415e-06 5.695e-06 4.0508e-06 00:00:04 1 200 8.8794e-05 5.6415e-06 5.695e-06 4.0507e-06 00:00:00 0
  2 comentarios
Stephen23
Stephen23 el 20 de Ag. de 2024
+1 very neat
Voss
Voss el 20 de Ag. de 2024
@Stephen23: Thanks!

Iniciar sesión para comentar.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by