How do I read a file in using fopen correctly
6 ビュー (過去 30 日間)
古いコメントを表示
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
2020 年 2 月 10 日
2 件のコメント
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
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
2020 年 2 月 10 日
1 件のコメント
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 Center および File 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!