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

조회 수: 2 (최근 30일)
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
Stephen23
Stephen23 2024년 6월 28일
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 2024년 6월 28일
편집: DGM 2024년 6월 28일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by