Error using horzcat Dimensions of arrays being concatenated are not consistent.

2 Ansichten (letzte 30 Tage)
Hi i tried to open this temperature data from ECMWF, the data is in the format of (.nc) NETCDF and want to save the data into array of column Latitude, Longitude, t2m, time. I used this code for other meteorological data and it worked. But, when I used this code to extract the ECMWF data and save it into ascii file, there's an error.
Here is the code
clear all
clc
ncfile = 'Temperature.nc' ; % nc file name
% To get information about the nc file
ncinfo(ncfile)
% % to display nc file
ncdisp(ncfile)
% % to read a vriable 'var' exisiting in nc file
temp = ncread(ncfile, 't2m');
Lat = ncread(ncfile, 'latitude');
Lon = ncread(ncfile, 'longitude');
Data = [Lat(:),Lon(:),temp(:)]; %SSSuncorrected(:),SSSanomaly(:),SST(:)];
save('temp.asc','Data','-ASCII');
And this is the error
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in extract (line 25)
Data = [Lat(:),Lon(:),temp(:)];
Can someone help me. I also attach the example of the data.
  2 Kommentare
Stephen23
Stephen23 am 28 Jun. 2024
unzip Temperature.zip
ncfile = 'Temperature.nc' ; % nc file name
% To get information about the nc file
%ncinfo(ncfile)
% % to display nc file
ncdisp(ncfile)
Source: /users/mss.system.578hx/Temperature.nc Format: 64bit Global Attributes: Conventions = 'CF-1.6' history = '2024-06-26 08:49:42 GMT by grib_to_netcdf-2.28.1: /opt/ecmwf/mars-client/bin/grib_to_netcdf -S param -o /cache/data2/adaptor.mars.internal-1719391782.1272883-14434-2-28bfb4b7-a74a-405d-b26c-f57f7fa168f9.nc /cache/tmp/28bfb4b7-a74a-405d-b26c-f57f7fa168f9-adaptor.mars.internal-1719391733.9327586-14434-1-tmp.grib' Dimensions: longitude = 7 latitude = 2 time = 252 Variables: longitude Size: 7x1 Dimensions: longitude Datatype: single Attributes: units = 'degrees_east' long_name = 'longitude' latitude Size: 2x1 Dimensions: latitude Datatype: single Attributes: units = 'degrees_north' long_name = 'latitude' time Size: 252x1 Dimensions: time Datatype: int32 Attributes: units = 'hours since 1900-01-01 00:00:00.0' long_name = 'time' calendar = 'gregorian' t2m Size: 7x2x252 Dimensions: longitude,latitude,time Datatype: int16 Attributes: scale_factor = 5.7354e-05 add_offset = 300.5921 _FillValue = -32767 missing_value = -32767 units = 'K' long_name = '2 metre temperature'
Your column vectors have 7, 2, and 3528 elements. How do you expect them to be horizontally concatenated?
DGM
DGM am 28 Jun. 2024
Bearbeitet: DGM am 28 Jun. 2024
You have location vectors of length 7 and 2.
You have a time vector of length 252.
Your temperature vector is of length 7*2*252 = 3528.
It doesn't make sense to concatenate those vectors. Use a struct or a cell array, or just store more than one variable in the .mat file.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by