Unzip and read gz files
28 views (last 30 days)
Show older comments
I'm trying to unzip and read in the data of some gz files from satellites. I think I've unzipped them using the 7-zip program, but when I try to read in the unzipped ascii file it reads as either one long character that I can't view, or a bunch of lines of text that are unintelligble. The file should have some lines of text describing the different variables and their units, then a bunch of rows of data. I want to be able to put each row of data into a different column in a table in the matlab workspace, and read the text so I know which column is which variable.
I can't attach the file directly as the file format isn't supported, but the link to acces the files is https://www.ngdc.noaa.gov/stp/space-weather/satellite-data/satellite-systems/gps/data/ . Look for a file with the format ns56_140105_v1.08.ascii.gz under the satellite 56.
Thank you for any help you can provide, I'm really stuck on this.
0 Comments
Answers (1)
Walter Roberson
on 12 Jun 2020
filename = 'ns56_140105_v1.08.ascii';
S = fileread(filename);
grouplabels = regexp(S, '#\s+"ELEMENT_LABELS":\[(?<labels>[^\]]+)', 'names', 'lineanchors');
varnames = cell2mat(regexp({varnames.vars},'(?<var>\w+)', 'names'));
numeric_part = cell2mat(textscan(S, '', 'CommentStyle','#', 'collectoutput', true));
YourTable = array2table(numeric_part, 'VariableNames', {varnames.var});
2 Comments
Walter Roberson
on 12 Jun 2020
varnames = cell2mat(regexp({grouplabels. labels},'(?<var>\w+)', 'names'));
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!