Combining plots of 3 different variables into a single plot
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to make a contour plot from an output netcdf file from my oceanic simulation. I am using a netcdf file and want a single plot with variables u,v and w . The dimension of variables I am using are as follows:
u
Size: 99x50x15x273
Dimensions: xi_u,eta_u,s_rho,ocean_time
Datatype: single
Attributes:
long_name = 'u-momentum component'
units = 'meter second-1'
time = 'ocean_time'
grid = 'grid'
location = 'edge1'
coordinates = 'lon_u lat_u s_rho ocean_time'
v
Size: 99x50x15x273
Dimensions: xi_v,eta_v,s_rho,ocean_time
Datatype: single
Attributes:
long_name = 'v-momentum component'
units = 'meter second-1'
time = 'ocean_time'
grid = 'grid'
location = 'edge1'
coordinates = 'lon_v lat_v s_rho ocean_time'
w
Size: 99x50x15x273
Dimensions: xi_u,eta_w,s_rho,ocean_time
Datatype: single
Attributes:
long_name = 'w-momentum component'
units = 'meter second-1'
time = 'ocean_time'
grid = 'grid'
location = 'edge1'
coordinates = 'lon_w lat_w s_rho ocean_time'
I am unable to write a matlab script for it that plots the combined effect of all these variables that is total = sqrt( u*u + v*v +w*w) into a plot.
It would be of great help if anyone could help me with the script as I am a beginner in MATLAB and need to do this for my project purpose. I have attached my file
I am attaching the code I wrote and I know it's not even correct to any degree:
File = ‘Lombok_roms_his.nc’
Lat = ncread(File,’lat’);
Lon = ncread(File,’lon’);
U = ncread(File,’u’);
V = ncread(File,’v’);
W = ncread(File,’w’);
Total = sqrt(U*U + V*V + W*W);
pcolor(lon,lat,Total(:,:,:,1)')
[m,n,p] = size(Total) ;
for i = 1:p
pcolor(Lat,Lon,Total(:,:,:i)')
shading interp
colorbar
drawnow
end
Respuestas (1)
Shubham Khatri
el 7 de Jun. de 2021
Hello,
I was not able to reproduce the scenario from the file provided. But to my understanding, this error occurs when the matrix dimensions are not same. You are performing additions in your code. To do this you need to have the exact same dimensions for all the matrices. Please take a look at the code below. For better understanding, if you change the 4th dimension of matirx A from 7 to 6, you ll get the same error.
A = zeros(2,3,5,7);
A(1,2,1,2) = 6;
A(1,1,5,6) = 5;
A(2,1,1,:) = pi;
B = zeros(2,3,5,7);
B(1,2,1,1) = 2;
B(1,1,5,6) = 4;
B(1,1,1,:) = 5;
Total = sqrt((A.*A) + (B.*B));
Hope it helps
Ver también
Categorías
Más información sobre NetCDF en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!