Combining plots of 3 different variables into a single plot

6 visualizzazioni (ultimi 30 giorni)
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
  1 Commento
Shankhaneel Basak
Shankhaneel Basak il 27 Mag 2021
When I run the above code written by me I get the following error and I am not sure how to remove this in order to achieve my target:
Array dimensions must match for binary array op.
Error in Untitled (line 7)
Total = sqrt((U.*U) + (V.*V) + (W.*W));

Accedi per commentare.

Risposte (1)

Shubham Khatri
Shubham Khatri il 7 Giu 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
  1 Commento
Shankhaneel Basak
Shankhaneel Basak il 8 Giu 2021
Thanks a lot for your answer but if it were a dimension error, then why does it happen in my case? u,v,w has the same size of 99x50x15x273 . The parameters are different but sizes are same. In that case addition or any such operation should be working, shouldn't it ?

Accedi per commentare.

Categorie

Scopri di più su Weather and Atmospheric Science in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by