- ‘lat_ncep’ has dimensions as 1 * 360
- ‘lon_ncep’ has dimensions as 1 * 180
Matrix Dimension Must Agree
8 次查看(过去 30 天)
显示 更早的评论
Hi I want to ask why 'matrix dimension must agree' is happen during running the coding for plotting the HDF5 data.
Here is my coding, i also attach the sample data
Error using pcolor (line 56)
Matrix dimensions must agree.
Error in hdf5 (line 13)
pcolor(lon_ncep,lat_ncep,var1);
% clear all
% close all
% clc
%
file=hdf5info('Q2014031.L3m_DAY_SCI_V5.0_SSS_1deg')
dset1=hdf5read(file.GroupHierarchy.Datasets(1));
dset2=hdf5read(file.GroupHierarchy.Datasets(2));
var1 = dset1
var1 = rot90(fliplr(var1));
var1(var1==-3.2767)=NaN;
lat_ncep = linspace(0,14,360);
lon_ncep = linspace(95,126,180);
pcolor(lon_ncep,lat_ncep,var1);
shading flat
c = colorbar;
ylabel(c,'C')
load coast
hold on
plot(long,lat,'black')
title('GSSTFM NCEP Sea Surface Temperature')
xlabel('degrees longitude')
ylabel('degrees latitude')
0 个评论
回答(1 个)
Sachin
2023-3-21
编辑:Sachin
2023-3-21
I understand that you are getting this error 'Matrix dimensions must agree'.
This is because of matrix dimensions of the matrices being used in your code do not match.Specifically, when you are using pcolor function then the size of inputs to the function must be of the same size.
Therefore, to resolve this error, you need to ensure that the matrices you are using with the 'pcolor' function have the same dimensions.
pcolor(lat_ncep,lon_ncep,var1) function have three inputs ‘lat_ncep’,’lon_ncep’ and ‘var1’ . So They all must be of the same dimensions.
Refer the following page for more information about pcolor:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 HDF5 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!