Matrix Dimensions must agree.. Help Please

Hello, I cannot seem to get my dimensions to agree. The error starts at line:
"v = (g/f)*dh_x./dx; % Meridional geostrophic velocity v"
%% #1 Figure 1
load xyeta.mat
figure
pcolor(x,y,eta)
shading interp
c = colorbar;
ylabel(c,'\eta (m)')
xlabel('Longitude (^oW)')
ylabel('Latitude (^oN)')
title('Sea Surface Elevation Map (in/m) / B. Guyton 05/03/2022')
hold on
%%%% #1 Figure 2
% geostrohpy, need to add f and rho
g = 9.81; % Gravitational acceleration (m/s2)
mlat = mean(y); % Mean lattitude of our area
dh_x = diff(eta,1,2);
dx = diff(x(1:2))*111320*cosd(mlat); % in meters
dh_y = diff(eta,1,1);
dy = diff(y(1:2))*110574;
%[FX,FY] = gradient(ssh);
Omega = 7.2921e-5; % Earth's rotation speed (rads/s)
f = 2*Omega*sind(mlat); % Coriollis Parameter
v = (g/f)*dh_x./dx; % Meridional geostrophic velocity v
u = -(g/f)*dh_y./dy; % Longitudinal geostrophic velocity u
% mid points of calculation
lat1 = (y(1:end-1) + y(2:end))/2;
lon1 = (x(1:end-1) + x(2:end))/2;
% throw away extra data so we have matching dimensions
v = v(2:end,:);
u = u(:,2:end);
% plot currents
hold on
quiver(lon1,lat1,u,v,'w')
xlim('auto')
ylim([-30.00 -0.13])
% plot zoom in area
plot([37 37 42 42 37], [-20 -15 -15 -20 -20],'r')
% zoomed in figure around eddy
figure
pcolor(x,y,eta)
shading flat
axis equal
c = colorbar;
ylabel(c,'h (m)')
hold on
scale=0.2; % Ploting scale
quiver(lon1,lat1,u*scale,v*scale, 0,'w')
axis([37 42 -20 -15])
quiver(38,-15.5,1*scale,0,0,'k')
text(38.1,-15.3,'1m/s')
ylabel(c,'\eta (m)')
xlabel('Longitude (degs)')
ylabel('Latitude (degs)')

Réponses (1)

Torsten
Torsten le 28 Avr 2022
Modifié(e) : Torsten le 28 Avr 2022
You work with vectors. So you must use
v = (g./f).*dh_x./dx; % Meridional geostrophic velocity v
u = -(g./f).*dh_y./dy; % Longitudinal geostrophic velocity u
instead of
v = (g/f)*dh_x./dx; % Meridional geostrophic velocity v
u = -(g/f)*dh_y./dy; % Longitudinal geostrophic velocity u

Catégories

En savoir plus sur Vector Fields dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by