Clear Filters
Clear Filters

Unable to understand how to use the function given on the site below

2 views (last 30 days)
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

Walter Roberson
Walter Roberson on 7 Nov 2022
Copy the matlab code from the site you linked to.
Then call the rdnim function passing in the name of the (unzipped) file. It does not matter that you do not see a file extension: the function does not care what the file extension is.
muhammad choudhry
muhammad choudhry on 7 Nov 2022
Hi, Thanks alot. took me little tile to get my head around it but got it there. It was something completely new for me and your previous posts really help to understand what I was looking for. Just one question in this case website provide the functions but what if I cam across the file without extension, what approch should I take... Any advice would be gold!
Walter Roberson
Walter Roberson on 7 Nov 2022
There is a difference between what a file extension for a file is, and what the format is of the contents of the file. In modern file systems, nearly any file extension can be used for any file.
You could take a .xlsx file you produced by Microsoft Excel and rename it to have a .jpg extension -- but doing so would not enable image processing code to open the Excel-produced file. The file content would stay the same no matter what file extension you renamed the file to.
Taking this further: it turns out that .xlsx files produced by Microsoft Excel are not really a distinct file type. Really what they are is renamed .zip files. Code that needs to read .xlsx files start by internally unzipping the .xlsx file to get at a directory that contains several files (most of which are .xml text files.) A number of different file formats are really renamed .zip files, such as .slx and .mlx files; a file extension that ends with "x" hints that the file might be one of these.
There is no central registry of file extensions and no requirement that all companies that use the same file extension must make their files compatible with the other companies that use the same extension. Expecially for .dat and .bin files -- those can be just about anything. For example, .mat files might be MATLAB save files or might be Microsoft Access Table files. Are two different .hdf files the same format? Not necessarily -- one of them might be HDF3 and another HDF4 for example.
So a file extension is at best a hint about which programs might be able to handle the file. You have to know what kind of data the file contains in order to actually use it.
A file that does not have any extension... has the same problem as all other files, that you need to know what kind of data the file contains. It just lacks the vague hint about which program to use.
In this particular case, you downloaded the zipped data files from a particular site, and that site documented which MATLAB functions to use to read the file. If you receive files in the future without an extension then investigate the file format with the site you get the files from.

Sign in to comment.

More Answers (1)

Bjorn Gustavsson
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,])
[cf1,cf2,cf3] = fileparts(; % 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
system(['gzip ',fullfile(currfile.folder,cf2)]) % after processing one file compress it again to reduce disk-usage
muhammad choudhry
muhammad choudhry on 7 Nov 2022
Hi, I have uncompressed the file by using the 7-zip that is not the problem. Problem is once I have uzip the file there is no extension for the file and whenever I am opening the data in .txt it is showing me gibrish rather then data. Please see the link below same thing happenening in my case.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!