Deleting specific numbers from a textfile
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I need help with what should be pretty simple but its been a while since I've used matlab so I am rusty. What I am trying to do is erase the first three numbers of every 'section' of numbers in the attached file below, and each section is separated by '#', so for example in the first couple of sections, I want the numbers that are bolded to be deleted:
103 0.005 3.000 121.1164 122.5661 1.5000 119.3625 120.1322 1.5000 117.6086 117.6982 1.5000 115.8548 115.2643 1.5000 114.1009 112.8304 1.5000 112.3470 110.3965 1.5000 110.5932 107.9626 1.5000 108.8393 105.5287 1.5000 107.0854 103.0947 1.5000 105.3316 100.6608 1.5000 103.5777 98.2269 1.5000 101.8238 95.7930 1.5000 100.0700 93.3591 1.5000 98.3161 90.9251 1.5000 96.5622 88.4912 1.5000 94.8084 86.0573 1.5000 93.0545 83.6234 1.5000 91.3006 81.1895 1.5000 89.5468 78.7556 1.5000 87.7929 76.3216 1.5000 86.0390 73.8877 1.5000 84.2852 71.4538 1.5000 82.5313 69.0199 1.5000 80.7774 66.5860 1.5000 79.0236 64.1521 1.5000 77.2697 61.7181 1.5000 75.5159 59.2842 1.5000 73.7620 56.8503 1.5000 72.0081 54.4164 1.5000 70.2543 51.9825 1.5000 68.5004 49.5485 1.5000 66.7465 47.1146 1.5000 64.9927 44.6807 1.5000 63.2388 42.2468 1.5000 61.4849 39.8129 1.5000 59.7311 37.3790 1.5000 57.9772 34.9450 1.5000 56.2233 32.5111 1.5000 54.4695 30.0772 1.5000 52.7156 27.6433 1.5000 50.9617 25.2094 1.5000 49.2079 22.7754 1.5000 47.4540 20.3415 1.5000 45.7001 17.9076 1.5000 43.9463 15.4737 1.5000 42.1924 13.0398 1.5000 40.4385 10.6059 1.5000 38.6847 8.1719 1.5000 36.9308 5.7380 1.5000 35.1769 3.3041 1.5000 33.4231 0.8702 1.5000 31.6692 -1.5637 1.5000 29.9154 -3.9976 1.5000 28.1615 -6.4316 1.5000 26.4076 -8.8655 1.5000 24.6538 -11.2994 1.5000 22.8999 -13.7333 1.5000 21.1460 -16.1672 1.5000 19.3922 -18.6012 1.5000 17.6383 -21.0351 1.5000 15.8844 -23.4690 1.5000 14.1306 -25.9029 1.5000 12.3767 -28.3368 1.5000 10.6228 -30.7707 1.5000 8.8690 -33.2047 1.5000 7.1151 -35.6386 1.5000 5.3612 -38.0725 1.5000 3.6074 -40.5064 1.5000 1.8535 -42.9403 1.5000 0.0996 -45.3743 1.5000 -1.6542 -47.8082 1.5000 -3.4081 -50.2421 1.5000 -5.1620 -52.6760 1.5000 -6.9158 -55.1099 1.5000 -8.6697 -57.5438 1.5000 -10.4236 -59.9778 1.5000 -12.1774 -62.4117 1.5000 -13.9313 -64.8456 1.5000 -15.6851 -67.2795 1.5000 -17.4390 -69.7134 1.5000 -19.1929 -72.1473 1.5000 -20.9467 -74.5813 1.5000 -22.7006 -77.0152 1.5000 -24.4545 -79.4491 1.5000 -26.2083 -81.8830 1.5000 -27.9622 -84.3169 1.5000 -29.7161 -86.7509 1.5000 -31.4699 -89.1848 1.5000 -33.2238 -91.6187 1.5000 -34.9777 -94.0526 1.5000 -36.7315 -96.4865 1.5000 -38.4854 -98.9204 1.5000 -40.2393 -101.3544 1.5000 -41.9931 -103.7883 1.5000 -43.7470 -106.2222 1.5000 -45.5009 -108.6561 1.5000 -47.2547 -111.0900 1.5000 -49.0086 -113.5240 1.5000 -50.7625 -115.9579 1.5000 -52.5163 -118.3918 1.5000 -54.2702 -120.8257 1.5000 -56.0241 -123.2596 1.5000 -57.7779 -125.6935 1.5000
#
85 0.214 3.000 -122.0384 109.2990 1.5000 -119.0768 108.8205 1.5000 -116.1152 108.3420 1.5000 -113.1536 107.8635 1.5000 -110.1920 107.3850 1.5000 -107.2304 106.9065 1.5000 -104.2688 106.4280 1.5000 -101.3072 105.9495 1.5000 -98.3457 105.4710 1.5000 -95.3841 104.9925 1.5000 -92.4225 104.5140 1.5000 -89.4609 104.0355 1.5000 -86.4993 103.5570 1.5000 -83.5377 103.0785 1.5000 -80.5761 102.6000 1.5000 -77.6145 102.1215 1.5000 -74.6529 101.6430 1.5000 -71.6913 101.1645 1.5000 -68.7297 100.6860 1.5000 -65.7681 100.2075 1.5000 -62.8065 99.7290 1.5000 -59.8449 99.2505 1.5000 -56.8833 98.7720 1.5000 -53.9217 98.2935 1.5000 -50.9602 97.8150 1.5000 -47.9986 97.3365 1.5000 -45.0370 96.8580 1.5000 -42.0754 96.3795 1.5000 -39.1138 95.9010 1.5000 -36.1522 95.4225 1.5000 -33.1906 94.9440 1.5000 -30.2290 94.4655 1.5000 -27.2674 93.9870 1.5000 -24.3058 93.5085 1.5000 -21.3442 93.0300 1.5000 -18.3826 92.5515 1.5000 -15.4210 92.0730 1.5000 -12.4594 91.5945 1.5000 -9.4978 91.1161 1.5000 -6.5362 90.6376 1.5000 -3.5747 90.1591 1.5000 -0.6131 89.6806 1.5000 2.3485 89.2021 1.5000 5.3101 88.7236 1.5000 8.2717 88.2451 1.5000 11.2333 87.7666 1.5000 14.1949 87.2881 1.5000 17.1565 86.8096 1.5000 20.1181 86.3311 1.5000 23.0797 85.8526 1.5000 26.0413 85.3741 1.5000 29.0029 84.8956 1.5000 31.9645 84.4171 1.5000 34.9261 83.9386 1.5000 37.8877 83.4600 1.5000 40.8493 82.9815 1.5000 43.8110 82.5030 1.5000 46.7727 82.0245 1.5000 49.7344 81.5460 1.5000 52.6963 81.0675 1.5000 55.6583 80.5889 1.5000 58.6206 80.1103 1.5000 61.5833 79.6316 1.5000 64.5470 79.1527 1.5000 67.5130 78.6735 1.5000 70.4980 78.1913 1.5110 73.4718 77.7108 1.6956 76.4439 77.2306 1.9846 79.4027 76.7525 2.4191 82.3587 76.2750 2.9402 85.2745 75.8040 3.6779 88.2348 75.3254 4.2950 91.1293 74.8579 3.0465 94.0862 74.3802 2.6630 97.0457 73.9020 2.1146 100.0193 73.4216 1.8045 102.9965 72.9405 1.5710 105.9857 72.4576 1.5000 108.9566 71.9776 1.5000 111.9221 71.4984 1.5000 114.8859 71.0196 1.5000 117.8487 70.5409 1.5000 120.8110 70.0623 1.5000 123.7729 69.5837 1.5000 126.7348 69.1052 1.5000
#
53 0.308 3.000 -122.7065 25.7417 1.5000 -120.4131 27.6756 1.5000 -118.1196 29.6095 1.5000 -115.8262 31.5434 1.5000 -113.5327 33.4774 1.5000 -111.2392 35.4113 1.5000 -108.9458 37.3452 1.5000 -106.6523 39.2791 1.5000 -104.3589 41.2130 1.5000 -102.0654 43.1470 1.5000 -99.7720 45.0809 1.5000 -97.4785 47.0148 1.5000 -95.1850 48.9487 1.5000 -92.8916 50.8826 1.5000 -90.5981 52.8166 1.5000 -88.3047 54.7505 1.5000 -86.0112 56.6844 1.5000 -83.7177 58.6183 1.5000 -81.4243 60.5522 1.5000 -79.1308 62.4862 1.5000 -76.8373 64.4201 1.5000 -74.5438 66.3541 1.5000 -72.2503 68.2881 1.5000 -69.9567 70.2221 1.5000 -67.6630 72.1562 1.5000 -65.3693 74.0903 1.5000 -63.0753 76.0247 1.5000 -60.7809 77.9594 1.5000 -58.4860 79.8946 1.5000 -56.1897 81.8309 1.5000 -53.8898 83.7702 1.5000 -51.5733 85.7235 1.5612 -49.2673 87.6681 1.7923 -46.9640 89.6103 2.1065 -44.6724 91.5426 2.6510 -42.3838 93.4725 3.0666 -40.1422 95.3627 4.2663 -37.8487 97.2966 3.8349 -35.5951 99.1969 2.9911 -33.3070 101.1263 2.4797 -31.0158 103.0583 2.0149 -28.7135 104.9997 1.7157 -26.4095 106.9425 1.5189 -24.0956 108.8936 1.5000 -21.7984 110.8307 1.5000 -19.5032 112.7661 1.5000 -17.2088 114.7009 1.5000 -14.9148 116.6352 1.5000 -12.6210 118.5694 1.5000 -10.3273 120.5035 1.5000 -8.0338 122.4375 1.5000 -5.7403 124.3715 1.5000 -3.4468 126.3054 1.5000
#
32 0.283 3.000 -52.1088 -123.1304 3.4512 -54.4480 -121.2904 4.4585 -56.7563 -119.4744 3.0487 -59.1097 -117.6230 2.7103 -61.4668 -115.7688 2.1301 -63.8328 -113.9076 1.8194 -66.2019 -112.0439 1.5761 -68.5786 -110.1742 1.5000 -70.9446 -108.3129 1.5000 -73.3060 -106.4553 1.5000 -75.6658 -104.5990 1.5000 -78.0248 -102.7432 1.5000 -80.3833 -100.8878 1.5000 -82.7416 -99.0326 1.5000 -85.0998 -97.1776 1.5000 -87.4578 -95.3226 1.5000 -89.8158 -93.4677 1.5000 -92.1737 -91.6128 1.5000 -94.5316 -89.7579 1.5000 -96.8895 -87.9030 1.5000 -99.2474 -86.0482 1.5000 -101.6052 -84.1933 1.5000 -103.9631 -82.3385 1.5000 -106.3210 -80.4836 1.5000 -108.6789 -78.6288 1.5000 -111.0367 -76.7739 1.5000 -113.3946 -74.9191 1.5000 -115.7525 -73.0642 1.5000 -118.1103 -71.2094 1.5000 -120.4682 -69.3545 1.5000 -122.8261 -67.4997 1.5000 -125.1839 -65.6448 1.5000
Thanks in advance to anyone who helps.
댓글 수: 0
채택된 답변
Amit Bhowmick
2021년 7월 5일
Try this and Adust output variable type as per your choice.
clear all
close all
clc
fid=fopen('experiment2.txt','r')
ln=1;
jj=1;
while(ln~=-1)
ln=fgets(fid);
if (ln~='#')
if (ln~=-1)
a=str2num(ln);
a=num2str(a(4:end));
L(jj)=string(a);
jj=jj+1;
end
end
end
fclose(fid)
댓글 수: 3
Amit Bhowmick
2021년 7월 5일
fid=fopen('AA.txt','r')
fib=fopen('A.txt','w')
ln=1;
jj=1;
while(ln~=-1)
ln=fgets(fid);
if (ln~='#')
if (ln~=-1)
a=str2num(ln);
a=num2str(a(4:end));
L(jj)=string(a);
b=fprintf(fib,string(a));
b=fprintf(fib,'\n');
jj=jj+1;
end
else
b=fprintf(fib,"#");
b=fprintf(fib,'\n');
end
end
fclose(fid)
fclose(fib)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!