필터 지우기
필터 지우기

Combining plots of 3 different variables into a single plot

조회 수: 3 (최근 30일)
Shankhaneel Basak
Shankhaneel Basak 2021년 5월 25일
댓글: Shankhaneel Basak 2021년 6월 8일
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
Shankhaneel Basak
Shankhaneel Basak 2021년 5월 27일
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));

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

답변 (1개)

Shubham Khatri
Shubham Khatri 2021년 6월 7일
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
Shankhaneel Basak
Shankhaneel Basak 2021년 6월 8일
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 ?

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

카테고리

Help CenterFile Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by