Could you please provide script to perform process described below. Many thanks in advance

1 次查看(过去 30 天)
In the 1.5 million line .txt file (only first 57 lines shown below)
Goal is to delete all columns except column four. Then move this data to the left.
I need to then save this file in .txt format so it can be opened (I.E. fopen) in a future matlab script
Example: The first column needs to look like this when script is performed on it.
0.06247
0.03747
0.03747
0.03747
...and so on
Here's the file
0.000000 0.06259 -0.06223 0.06247 0.99601 0.03158 0.00018 22.10 22.15 0
0.040001 0.03756 -0.04984 0.03747 0.99622 0.03219 0.00018 22.07 22.15 0
0.080000 0.03756 -0.04984 0.03747 0.99562 0.03260 0.00059 22.07 22.15 0
0.120000 0.03756 -0.04984 0.03747 0.99602 0.03239 -0.00002 22.07 22.15 0
0.160000 0.05005 -0.03727 0.03747 0.99581 0.03219 -0.00002 22.07 22.15 0
0.200000 0.05006 -0.04977 0.03748 0.99622 0.03198 0.00018 22.03 22.15 0
0.240000 0.06256 -0.04971 0.03748 0.99643 0.03219 -0.00003 22.10 22.15 0
0.280000 0.06256 -0.04971 0.03748 0.99622 0.03219 0.00038 22.03 22.15 0
0.320000 0.03757 -0.04984 0.04997 0.99643 0.03260 -0.00023 22.10 22.15 0
0.360001 0.06256 -0.04971 0.03748 0.99581 0.03219 -0.00002 22.07 22.15 0
0.400000 0.03757 -0.04984 0.04997 0.99602 0.03260 -0.00023 22.03 22.15 0
0.440000 0.03756 -0.04984 0.03747 0.99582 0.03239 0.00018 22.03 22.15 0
0.480000 0.05007 -0.04978 0.04998 0.99561 0.03219 -0.00002 22.07 22.15 0
0.520000 0.05005 -0.03727 0.03749 0.99602 0.03178 -0.00003 22.10 22.15 0
0.560000 0.05006 -0.04977 0.03748 0.99602 0.03260 0.00018 22.07 22.15 0
0.600000 0.06257 -0.04972 0.04998 0.99622 0.03158 -0.00023 22.07 22.15 0
0.640000 0.06256 -0.04971 0.03748 0.99541 0.03219 -0.00002 22.03 22.15 0
0.680000 0.05007 -0.04978 0.04998 0.99582 0.03239 -0.00002 22.10 22.16 0
0.720000 0.03757 -0.03734 0.04998 0.99601 0.03137 0.00017 22.07 22.16 0
0.760000 0.05007 -0.04978 0.04998 0.99622 0.03178 0.00058 22.07 22.15 0
0.800000 0.05007 -0.04978 0.04998 0.99623 0.03280 0.00059 22.07 22.16 0
0.840000 0.06257 -0.04972 0.04998 0.99622 0.03178 0.00018 22.10 22.16 0
0.880000 0.05007 -0.04978 0.04998 0.99643 0.03219 0.00018 22.07 22.17 0
0.920000 0.05007 -0.04978 0.04998 0.99642 0.03178 0.00017 22.10 22.17 0
0.960001 0.06257 -0.04972 0.04998 0.99622 0.03219 0.00018 22.07 22.17 0
1.000001 0.05007 -0.04978 0.04998 0.99602 0.03219 0.00038 22.07 22.17 0
1.040000 0.05007 -0.04978 0.04998 0.99622 0.03219 0.00038 22.10 22.17 0
1.080000 0.06257 -0.04972 0.04998 0.99581 0.03199 -0.00003 22.07 22.17 0
1.120001 0.03757 -0.04984 0.04997 0.99602 0.03178 0.00018 22.13 22.17 0
1.160000 0.03757 -0.04984 0.04997 0.99643 0.03198 0.00018 22.10 22.17 0
1.200001 0.03756 -0.04984 0.03747 0.99581 0.03198 0.00018 22.07 22.17 0
1.240000 0.03757 -0.04984 0.04997 0.99622 0.03219 -0.00043 22.07 22.17 0
1.280000 0.05007 -0.04978 0.04998 0.99643 0.03239 0.00018 22.07 22.17 0
1.320000 0.06256 -0.04971 0.03748 0.99582 0.03260 0.00018 22.10 22.18 0
1.360000 0.05006 -0.04977 0.03748 0.99622 0.03198 0.00018 22.13 22.18 0
1.400000 0.06256 -0.06221 0.03747 0.99582 0.03239 0.00100 22.07 22.18 0
1.440000 0.05006 -0.04977 0.03748 0.99602 0.03219 0.00018 22.10 22.17 0
1.480001 0.05007 -0.04978 0.04998 0.99581 0.03219 -0.00002 22.17 22.17 0
1.520000 0.06257 -0.04972 0.04998 0.99582 0.03219 0.00099 22.10 22.17 0
1.560000 0.05006 -0.04977 0.03748 0.99602 0.03239 0.00018 22.07 22.17 0
1.600001 0.03756 -0.04984 0.03747 0.99622 0.03198 -0.00003 22.13 22.17 0
1.640000 0.05009 -0.03729 0.06249 0.99581 0.03198 0.00038 22.13 22.17 0
1.680000 0.05007 -0.04978 0.04998 0.99663 0.03239 0.00018 22.10 22.17 0
1.720001 0.05007 -0.04978 0.04998 0.99581 0.03198 0.00018 22.13 22.17 0
1.760000 0.05005 -0.03727 0.03749 0.99602 0.03219 0.00079 22.13 22.17 0
1.800000 0.05007 -0.04978 0.04998 0.99623 0.03260 -0.00002 22.07 22.17 0
1.840000 0.06255 -0.03721 0.03750 0.99561 0.03219 0.00038 22.10 22.17 0
1.880001 0.05007 -0.04978 0.04998 0.99602 0.03260 0.00018 22.13 22.17 0
1.920000 0.06257 -0.03722 0.05000 0.99602 0.03219 0.00018 22.13 22.18 0
1.960000 0.06257 -0.04972 0.04998 0.99622 0.03178 0.00058 22.13 22.18 0
2.000001 0.05007 -0.04978 0.04998 0.99622 0.03219 -0.00023 22.10 22.18 0
2.040000 0.05007 -0.04978 0.04998 0.99663 0.03178 -0.00023 22.17 22.18 0
2.080000 0.05006 -0.04977 0.03748 0.99622 0.03198 0.00038 22.13 22.18 0
2.120000 0.05007 -0.04978 0.04998 0.99602 0.03219 0.00059 22.10 22.18 0
2.160000 0.06256 -0.04971 0.03748 0.99622 0.03239 -0.00023 22.10 22.18 0
2.200000 0.05005 -0.03727 0.03749 0.99602 0.03219 -0.00023 22.07 22.18 0
2.240001 0.05007 -0.04978 0.04998 0.99643 0.03198 0.00038 22.07 22.1

采纳的回答

Duane Melvin
Duane Melvin 2022-12-5
data_file=load('SCH63_11_17_22_backup_workingq.txt');
j=[2]; %define column number
colm_data=data_file(:,j); % Column data for further use
writematrix(colm_data, 'GZ.txt');

更多回答(1 个)

Torsten
Torsten 2022-12-1
A = rand(7)
A = 7×7
0.9251 0.7288 0.0045 0.7998 0.9367 0.6610 0.3797 0.0627 0.6351 0.9058 0.5269 0.9427 0.0369 0.8074 0.2940 0.0416 0.8010 0.1406 0.7628 0.1347 0.1148 0.1904 0.5255 0.6585 0.9014 0.0839 0.3026 0.5115 0.0925 0.3903 0.6269 0.6232 0.7953 0.5247 0.0124 0.6448 0.5859 0.7592 0.3045 0.2755 0.5507 0.1936 0.4970 0.2017 0.9420 0.7136 0.4950 0.4853 0.7443
A = A(:,4)
A = 7×1
0.7998 0.5269 0.1406 0.9014 0.6232 0.3045 0.7136
writematrix(A, 'A.txt')
  2 个评论
Duane Melvin
Duane Melvin 2022-12-5
The answer did not work but this one did. This script below worked. I found it removes all columns except the column number in j=[] in this case, column 2 data is preserved
then it writes a new .txt file named GZ with column 2 moved over to the far left. Perfect
data_file=load('SCH63_11_17_22_backup_workingq.txt');
j=[2]; %define column number
colm_data=data_file(:,j); % Column data for further use
writematrix(colm_data, 'GZ.txt');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品


版本

R2006b

Community Treasure Hunt

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

Start Hunting!

Translated by