Unzip and read gz files

8 次查看(过去 30 天)
Cordelia David
Cordelia David 2020-6-12
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.

回答(1 个)

Walter Roberson
Walter Roberson 2020-6-12
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 个评论
Cordelia David
Cordelia David 2020-6-12
Hey Walter, thank you for your answer. After trying this code, I got the error: Unable to resolve the name varnames.vars. This occurs at line varnames = cell2mat(regexp({varnames.vars},'(?<var>\w+)', 'names'));
Walter Roberson
Walter Roberson 2020-6-12
varnames = cell2mat(regexp({grouplabels. labels},'(?<var>\w+)', 'names'));

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by