Error using ' TRANSPOSE does not support N-D arrays. Use PAGETRANSPOSE/PAGECTRANSPOSE to transpose pages or PERMUTE to reorder dimensions of N-D arrays.
조회 수: 11 (최근 30일)
이전 댓글 표시
The data is from Copernicus, but sea surface height (SHW) is a 3D matirx
clear
clc
dir = 'C:\Users\Madison-Riley\Downloads\';
ncfile = 'PotentialTemp.nc'; % name of data file from copernicus
ncdisp([dir,ncfile])
lon = ncread([dir,ncfile], 'longitude');
lat = ncread([dir,ncfile], 'latitude');
depth = ncread([dir,ncfile], 'depth');
time = ncread([dir,ncfile], 'time');
% note 'squeeze' function gets rid of the single dimension (depth=1):
temp= squeeze(ncread([dir,ncfile], 'thetao')); % Sea water potential temperature (long,lat,depth(=1),time)
clf
% plot temp for time t=1:
pcolor(lon,lat,temp(:,:,1)');
shading flat;
colorbar
댓글 수: 2
Cris LaPierre
2023년 6월 3일
I don't see a variable SHW in your code. The only transpose operation I see is a 2D array, which should work.
Please share the full error message (all the red text). Please save your variable lon, lat, depth, time, and temp to a mat file and attach that to your post using the paperclip icon.
채택된 답변
Walter Roberson
2023년 6월 3일
Your nc file has lat, long, one depth, and multiple times, making it a 4 dimensional array. You are trying to pcolor() the entire 4d array at the same time. pcolor can only handle 2d data.
The error with transpose is a side show. You could permute() [2 1 3 4] instead of ' but the resulting array would still be 4d and pcolor cannot handle that. You should extract the data for one time for each pcolor, possibly looping animating over time
댓글 수: 0
추가 답변 (1개)
Hiro Yoshino
2023년 6월 3일
I could reproduce the same error message as follows:
X = rand(3,3,4)
transpose(X)
The best bet is replace this with pagetranspose as it says:
pagetranspose(X)
댓글 수: 3
Cris LaPierre
2023년 6월 3일
편집: Cris LaPierre
2023년 6월 3일
Please share the full error message (all the red text). Please save your variables lon, lat, time, and SHW to a mat file and attach that to your post using the paperclip icon.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!