Unable to understand how to use the function given on the site below
Show older comments
Hi,
I am trying to understand the functions and how to use them given on the site below.
Basically, this site have the rainfall data which is in .gz file and these are the matlab function given on the site to work with, but I am unable to understand how to use them, if there is any expert here can suggest me how to use them function to read the .gz file it will save me alot of time and give me a good start. I have been googling since yesterday and still lost.
Found a very useful link:
which is doing the same thing I am after but the file format is .ascii and @Walton Robinson gave a very good explanation but in my case files are.gz and I am not sure how to convert them files into something useful (possibly csv).
The attach notepad file is what I am getting after extracting from gz format which is just gibrish as soon as I extracted, I lost the extension.
It is not letting me upload the file here with error!
File format is unsupported for file:2022_329x432. Use any of these formats:.bmp, .csv, .fig, .gif, .jpg, .jpeg, .m, .mat, .mdl, .mlapp, .mlx, .sfx, .slx, .sbproj, .pdf, .png, .txt, .xls, .xlsx, .zip
Hope I will get some good advice here"
Accepted Answer
More Answers (1)
Bjorn Gustavsson
on 7 Nov 2022
files with the extension .gz are typically compressed with gzip, that use the Lempel-Ziv coding. The most effective way to handle this problem is to simply uncompress the files at once - provided you have disp-space to store the files in an uncompressed format. To do this, simply do:
$ prompt> gunzip *.gz
from a terminal in the data-directory. If you use MS-windows there should be some shell-facility, if not you should be able to do this uncompression from a file-manager?
If you cannot expand all files then you might have to do them one-by-one in you matlab-script. Perhaps something like this:
datafiles = dir('*.gz'); % or however you select the files to process.
for iDF = 1:numel(datafiles)
currfile = datafiles(iDF);
system(['gunzip ',fullfile(currfile.folder,currfile.name)])
[cf1,cf2,cf3] = fileparts(currfile.name); % cf2 will have the name of the file after gunzipping
disp(fullfile(currfile.folder,cf2)) % this should be the full name of the uncompressed file
cData = load_your_data(fullfile(currfile.folder,cf2)) % or however you load one of your data-files
Your_processing(cData)
system(['gzip ',fullfile(currfile.folder,cf2)]) % after processing one file compress it again to reduce disk-usage
end
HTH
2 Comments
muhammad choudhry
on 7 Nov 2022
Bjorn Gustavsson
on 7 Nov 2022
Follow Walter's recommendation.
Categories
Find more on Spreadsheets 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!