.GRD format read and write error

4 views (last 30 days)
Balaji L
Balaji L on 6 Jun 2021
Answered: Arjun on 27 Feb 2025
I have temperature data in .grd format. Need to extract data in the binary file to matrix in workspace and write the entire data into .csv format.
I have tried one solution from matlab community (grdread2 function) and getting this error.
>> Z = grdread2('Maxtemp_MaxT_2005.GRD')
Error using netcdflib
The NetCDF library encountered an error during execution of 'open'
function - 'Unknown file format (NC_ENOTNC)'.
Error in netcdf.open (line 67)
[varargout{:}] = netcdflib ( 'open', filename, varargin{1} );
Error in grdread2 (line 61)
ncid = netcdf.open(file, 'NC_NOWRITE');

Answers (1)

Arjun
Arjun on 27 Feb 2025
I understand that you want to read a file which is in ".GRD" format and then write it into ".CSV" format but you are encountering issues while opening the ".GRD" file.
You can open the ".GRD" file using "fopen" function of MATLAB and then read using "fread" function of MATLAB. Kindly refer to the following MATLAB Answer for more insights: https://www.mathworks.com/matlabcentral/answers/1464624-unable-to-read-the-grd-file-using-grdread2-m-function
Once you have read the data from the file then you can use the "writematrix" function of MATLAB to write data into ".CSV" format.
Here is a small code snippet which might be useful:
filename=['XYZ.grd'];
fileID = fopen(filename);
output = fread(fileID,'float');
writematrix(output,'new.csv');
Kindly refer to the documentation of the functions used above:
I hope this helps!

Community Treasure Hunt

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

Start Hunting!