Make a plt from a 4-D multi array variable from nc file
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have a nc file with:
Dimensions:
time = 8
depth = 48
latitude = 109
longitude = 25
and make this:
u='global-reanalysis-phy-001-030-daily_1591804259623.nc'
ncdisp(u)
east = ncread(u,'uo');
lat = ncread(u,'latitude');
lon = ncread(u,'longitude');
time=ncread(u, 'time');
depth=ncread(u, 'depth');
dtime = datetime(1950, 1, 1, time, 0, 0);
jd=juliandate(dtime);
plot(lat, east(:,:,15,1));
east is a 4-D 8371200 double
But I want a plot (surfc) in time, this 8 days, latitude, one depth (lets say 48, the last) and the east variable that is a velocity m/s.
Any idea? What I should do with east variable? squeeze, quiver, etc realy dont know or find solution
Thanks.
댓글 수: 1
OP commented:
the plot(lat, east(:,:,15,1)) is working but only for one day if I change 1 for : then the error
Data cannot have more than 2 dimensions.
채택된 답변
ncfile = "global-reanalysis-phy-001-030-daily_1591804259623.nc";
time = ncread(ncfile,'time') ;
depth = ncread(ncfile,'depth') ;
lat = ncread(ncfile,'latitude') ;
lon = ncread(ncfile,'longitude') ;
u = ncread(ncfile,'uo') ;
% plots
for i = 1:length(time) % time loop
for j = 1:length(depth) % depth loop
z = u(:,:,j,i)' ; % extract the matrix here
pcolor(lon,lat,z) ;
colorbar
shading interp
xlabel('lon')
ylabel('lat')
title(sprintf('time = %d, depth = %d',i,j))
drawnow
end
end
댓글 수: 17
Thanks for you answer, I try but this came:
>> surf(lon,lat,east(:,:,1))
Error using surf (line 74)
Data dimensions must agree.
>> pcolor(lon,lat,east(:,:,2))
Error using pcolor (line 59)
Matrix dimensions must agree.
I make the squeeze .
Any idea?
try transposing the matrix..
surf(lon,lat,east(:,:,1)')
If not working share the dimensions of each variable here..
Thanks!
Here is the file
What i want is a plot in 2D
x=time
y=latitude
z=east
at specific depth.
Edited the answer.
ok! I try it runs with out error but the plot is empty.
the z matrix is NaN
All the matrices are not NaN....when depth is increasing....data is having NaN's....see the plot, it is in a loop..it is plotting all the values..
I add this to your answer:
nx = length(lon);
ny = length(lat);
nd=length(depth);
nt=length(time);
that I saw you make in other question and works but is like running the time and depths like animation
but still the cordinates are lat and long
Okay..I got it..you want to plot for specific depth, all the time data...
For this case, you need to fix the range of lat and lon...
ok! yes I understand so how can I make the plot time vs lat with u as 3 variable
ncfile = "global-reanalysis-phy-001-030-daily_1591804259623.nc";
time = ncread(ncfile,'time') ;
depth = ncread(ncfile,'depth') ;
lat = ncread(ncfile,'latitude') ;
lon = ncread(ncfile,'longitude') ;
u = ncread(ncfile,'uo') ;
% plots
for i = 1:length(lon)
ud = squeeze(u(:,i,1,:)) ;
pcolor(lon,time,ud')
shading interp ;
colorbar
title(sprintf("depth = 1, lat rows = %d",i)) ;
drawnow
pause
end
This is called Hovmoller diagrams ..am I right?
ok! thanks I think I can change to axe x time and to y latitude
great!
Yes Hovmoller! I just start with this this week and try with few data now came the big things...
so what is doing: ud = squeeze(u(:,i,1,:))
thanks!
You can try it your self......check the dimensions before and after squeeze.
squeeze : it will remove the unwanted extra dimensions
yes! thanks a lot!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

