Matrix Dimension Must Agree

조회 수: 5 (최근 30일)
MAT NIZAM UTI
MAT NIZAM UTI 2023년 3월 21일
댓글: MAT NIZAM UTI 2023년 3월 21일
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')

답변 (1개)

Sachin
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.
  • ‘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
MAT NIZAM UTI
MAT NIZAM UTI 2023년 3월 21일
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 ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 HDF5에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by