Unable to understand how to use the function given on the site below
조회 수: 4 (최근 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!