필터 지우기
필터 지우기

How do I read a file in using fopen correctly

조회 수: 6 (최근 30일)
Daniel Montgomery
Daniel Montgomery 2020년 2월 9일
댓글: Walter Roberson 2020년 2월 10일
I am trying to read in spectroscopic data in using fopen and place the data into the y array. The file dimensions are 69 * 22533. What am I doing incorrectly?
x = 1:5; %5
y = zeros(69,22533);
fileID = fopen('Pandora166s1_LabGSFC_20200115_L0_subset (1).txt','w');
fprintf(fileID,'%d %4.4f\n',y);
fclose(fileID);
  댓글 수: 3
Daniel Montgomery
Daniel Montgomery 2020년 2월 10일
It is an index less text file. My first character is a string I want to import the data from matlab. The data in Y would start at zero and start a new row at the 69th character.
Walter Roberson
Walter Roberson 2020년 2월 10일
Please show an extract of the file.

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

채택된 답변

Daniel Montgomery
Daniel Montgomery 2020년 2월 10일
I did not know a consistent number of characters was required for reading in a file. What would be the best way to to import this to get cell seperated values? I am trying to isolate a range of cloumns for data analaysis.
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 2월 10일
Consistency of line length is not usually required, but when we asked about the format you said "The data in Y would start at zero and start a new row at the 69th character". That would not make sense unless you had a fixed width line.
Walter Roberson
Walter Roberson 2020년 2월 10일
What you attached has three columns per line, such as "Instrument", "type:" and "Pandora". But that looks pretty accidental to me and it looks more likely that you have a parameter name phrase followed by : then a parameter value that is not necessarily numeric. Because it is not numeric we have to guess that in non-numeric cases you want until the end of the line. The example you give only shows one numeric value on any line but we can speculate that there might be lines with multiple numbers.

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

추가 답변 (1개)

Daniel Montgomery
Daniel Montgomery 2020년 2월 10일
Instrument type: Pandora
Instrument number: 166
Spectrometer number: 1
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 2월 10일
That is not a consistent number of characters per row?
What would you expect the output to be for that extract?

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

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by