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!