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
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)
Your column vectors have 7, 2, and 3528 elements. How do you expect them to be horizontally concatenated?
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 Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!