Azzera filtri
Azzera filtri

How to sum up each data value in 1 txt file?

2 visualizzazioni (ultimi 30 giorni)
Hello, How can I read the txt file and sum third column values of each first and second row (dryz + wetz) into 1 added value and make it to another txt file?

Risposta accettata

Voss
Voss il 23 Giu 2022
data = readmatrix('VMF1.BAKO.txt');
odd_rows = data(1:2:end,3);
even_rows = data(2:2:end,3);
% add each dry element to its corresponding wet element
writematrix(odd_rows+even_rows,'sum_dry_and_wet.txt')
type sum_dry_and_wet.txt % see the result
2.63515953438603 2.63513965511074 2.63513667431955 2.63513369352797 2.63513071273678 2.63512773194519 2.635124751154 2.63512177036241 2.63511878957123 2.63511580877964 2.63511282798845 2.63510984719726 2.63510686640568 2.63510388561449 2.6351009048229 2.63509792403171 2.63509494324012 2.63509196244893 2.63508898165735 2.63508600086616 2.63508302007497 2.63508003928338 2.63507705849219 2.63507407770061 2.63507109690942 2.63506811611783 2.63506513532664 2.63506215453505 2.63505917374387 2.63505619295268 2.63505321216109 2.6350502313699 2.63504725057832 2.63504426978713 2.63504128899554 2.63503830820435 2.63503532741276 2.63503234662158 2.63502936583039 2.6350263850388 2.63502340424761 2.63502042345602 2.63501744266484 2.63501446187325 2.63501148108206 2.63500850029047 2.63500551949928 2.6350025387081 2.63499955791651 2.63499657712532 2.63499359633373 2.63499061554254 2.63498763475096 2.63498465395977 2.63498167316818 2.63497869237699 2.6349757115858 2.63497273079422 2.63496975000303 2.63496676921144 2.63496378842025 2.63496080762866 2.63495782683748 2.63495484604589 2.6349518652547 2.63494888446351 2.63494590367192 2.63494292288074 2.63493994208915 2.63493696129796 2.63493398050637 2.63493099971519 2.6349280189236 2.63483235516345 2.63473077547474 2.6346291957724 2.63452761608369 2.63442603638136 2.63432445669264 2.63422287699031 2.6341212973016 2.63401971759926 2.63391813791055 2.63381655822184 2.63371497851951 2.63361339883079 2.63351181912846 2.63341023943975 2.63330865973741 2.6332070800487 2.63310550034637 2.63300392065766 2.63290234096895 2.63280076126661 2.6326991815779 2.63259760187557 2.63249602218685 2.63239444248452 2.63229286279581 2.63219128309347 2.63208970340476 2.63198812371605 2.63188654401371 2.631784964325 2.63168338462267 2.63158180493396 2.63148022523162 2.63137864554291 2.63127706584058 2.63117548615187 2.63107390646315 2.63097232676082 2.63087074707211 2.63076916736977 2.63066758768106 2.63056600797873 2.63046442829002 2.63036284858768 2.63026126889897 2.63015968921026 2.63005810950792 2.62995652981921 2.62985495011688 2.62975337042817 2.62965179072583 2.62955021103712 2.62944863133479 2.62934705164607 2.62924547195736 2.62914389225503 2.62904231256632 2.62894073286398 2.62883915317527 2.62873757347294 2.62863599378422 2.62853441408189 2.62843283439318 2.62833125470447 2.62822967500213 2.62812809531342 2.62802651561109 2.62792493592238 2.62782335622004 2.62772177653133 2.627620196829 2.62772132049919 2.62783538266934 2.6279494448548 2.62806350702495 2.6281775692104 2.62829163138056 2.62840569356601 2.62851975573617 2.62863381792162 2.62874788009178 2.62886194226194 2.62897600444739 2.62909006661755 2.629204128803 2.62931819097315 2.62943225315861 2.62954631532876 2.62966037751422 2.62977443968437 2.62988850185453 2.63000256403998 2.63011662621014 2.63023068839559 2.63034475056575 2.6304588127512 2.63057287492136 2.63068693710681 2.63080099927697 2.63091506144712 2.63102912363258 2.63114318580273 2.63125724798819 2.63137131015834 2.63148537234379 2.63159943451395 2.6317134966994 2.63182755886956 2.63194162103972 2.63205568322517 2.63216974539533 2.63228380758078 2.63239786975093 2.63251193193639 2.63262599410654 2.632740056292 2.63285411846215 2.63296818063231 2.63308224281776 2.63319630498792 2.63331036717337 2.63342442934353 2.63353849152898 2.63365255369914 2.63376661588459 2.63388067805475 2.6339947402249 2.63410880241036 2.63422286458051 2.63433692676597 2.63445098893612 2.63456505112158 2.63467911329173 2.63479317547718 2.63490723764734 2.6350212998175 2.63513536200295 2.63524942417311 2.63536348635856 2.63547754852872 2.63559161071417 2.63570567288432 2.63581973506978 2.63553005316954 2.63521460039569 2.63489914757955 2.63458369480571 2.63426824198956 2.63395278921572 2.63363733639957 2.63332188362573 2.63300643080958 2.63269097803574 2.6323755252619 2.63206007244575 2.63174461967191 2.63142916685576 2.63111371408192 2.63079826126578 2.63048280849193 2.63016735567579 2.62985190290195 2.6295364501281 2.62922099731196 2.62890554453812 2.62859009172197 2.62827463894813 2.62795918613198 2.62764373335814 2.62732828054199 2.62701282776815 2.62669737499431 2.62638192217816 2.62606646940432 2.62575101658818 2.62543556381433 2.62512011099819 2.62480465822435 2.6244892054082 2.62417375263436 2.62385829986052 2.62354284704437 2.62322739427053 2.62291194145438 2.62259648868054 2.62228103586439 2.62196558309055 2.6216501302744 2.62133467750056 2.62101922472672 2.62070377191057 2.62038831913673 2.62007286632059 2.61975741354675 2.6194419607306 2.61912650795676 2.61881105514061 2.61849560236677 2.61818014959293 2.61786469677678 2.61754924400294 2.61723379118679 2.61691833841295 2.6166028855968 2.61628743282296 2.61597198000681 2.61565652723297 2.61534107445913 2.61502562164299 2.61471016886914 2.614394716053 2.61407926327916 2.61376381046301 2.61344835768917 2.61313290487302
% - or -
% add all dry elements and add all wet elements
writematrix([sum(odd_rows); sum(even_rows)],'sum_dry_and_sum_wet.txt')
type sum_dry_and_sum_wet.txt % see the result
656.504201744706 103.741030417315

Più risposte (0)

Categorie

Scopri di più su Large Files and Big Data in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by