How do I read a file in using fopen correctly
Show older comments
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 Comments
Walter Roberson
on 9 Feb 2020
That is code to write a lot of zeroes into a file, not to read from a file.
Your format hints that in your file the first column is an integer. Is that some kind of index? If so then how does it relate to the location to place the data into y?
Daniel Montgomery
on 10 Feb 2020
Walter Roberson
on 10 Feb 2020
Please show an extract of the file.
Accepted Answer
More Answers (1)
Daniel Montgomery
on 10 Feb 2020
0 votes
1 Comment
Walter Roberson
on 10 Feb 2020
That is not a consistent number of characters per row?
What would you expect the output to be for that extract?
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!