Matrix Dimension Must Agree

8 views (last 30 days)
MAT NIZAM UTI
MAT NIZAM UTI on 21 Mar 2023
Commented: MAT NIZAM UTI on 21 Mar 2023
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')

Answers (1)

Sachin
Sachin on 21 Mar 2023
Edited: Sachin on 21 Mar 2023
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.
  • ‘lat_ncep’ has dimensions as 1 * 360
  • ‘lon_ncep’ has dimensions as 1 * 180
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:
  1 Comment
MAT NIZAM UTI
MAT NIZAM UTI on 21 Mar 2023
Thank you for the response,
Can I ask another question, may I know if there any way for me to arrange the data into Lat, Long, dset1 matrix ?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!