Unable to understand how to use the function given on the site below
3 次查看(过去 30 天)
显示 更早的评论
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"
0 个评论
采纳的回答
Walter Roberson
2022-11-7
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.
2 个评论
Walter Roberson
2022-11-7
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.
更多回答(1 个)
Bjorn Gustavsson
2022-11-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 HDF5 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!