필터 지우기
필터 지우기

Multiply certain column in a text file by a constant and have it implemented in text file itself

조회 수: 1 (최근 30일)
I need to multiply column 3 of the attached text file by 15 and have it write into the file itself (not just stay as a variable in matlab). How would I go about doing this?
File is attached.

답변 (2개)

Adam
Adam 2015년 8월 3일
편집: Adam 2015년 8월 3일
doc textscan
doc fprintf
should do the job. I assume you know how to multiply by 15.
  댓글 수: 4
jgillis16
jgillis16 2015년 8월 3일
I posted my file, and gave instructions on what I am trying to achieve. With the necessary skills, that is enough specific information for some people.
Adam
Adam 2015년 8월 3일
Well obviously if you just want others to do all the work for you. People usually get help quicker by posting their current solution and why it doesn't work, but if you aren't in a hurry someone might do all the work for you instead.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2015년 8월 3일
Updating a text file "in place" seldom works, even if you fseek() backwards to position yourself to the start of the field to write the variable back to. In order to update a text file "in place" what you output must have exactly the same number of characters as what is input. So for example if your field is 1.0 then because the output is 15.0 which takes one more output location, you cannot just overwrite starting from the 1.0 (not and have the overwrite work.)
  댓글 수: 2
jgillis16
jgillis16 2015년 8월 3일
Say I took the variable: GalList.ra = data{3}; and multiplied it by 15 which led to the variable: GalList.ra2 = GalList.ra * 15;
There would be no way to replace the original variable with the new variable with the same dimensions but just multiplied by 15 in the original text file?
Or, instead could I create a new text file with all the columns as the original text file but with column 3 modified by multiplying column 3 by 15?
Walter Roberson
Walter Roberson 2015년 8월 4일
Given the text file you have now posted, No, you cannot update that file "in place", changing only the one column. You need to copy the file with the other fields remaining the same.
This is not a MATLAB restriction: this is fundamental to the way that operating systems implement text files as plain streams of characters, which has been the case for every file system for Microsoft Windows, for every file system (that I know of) for Linux, and for every file system for OS-X. One of the very first operating systems that MATLAB was ever supported on, DEC VMS, supported two ways of building text files, one of which did support updates in place, but MATLAB never supported that operating system feature (which was already falling out of favor by the time that MATLAB was first implemented.)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by