Error using horzcat Dimensions of arrays being concatenated are not consistent.
2 views (last 30 days)
Show older comments
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 Comments
Stephen23
on 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)
Your column vectors have 7, 2, and 3528 elements. How do you expect them to be horizontally concatenated?
DGM
on 28 Jun 2024
Edited: DGM
on 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.
Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!