Error using ' TRANSPOSE does not support N-D arrays. Use PAGETRANSP​OSE/PAGECT​RANSPOSE to transpose pages or PERMUTE to reorder dimensions of N-D arrays.

3 vues (au cours des 30 derniers jours)
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 commentaires
Cris LaPierre
Cris LaPierre le 3 Juin 2023
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.
Madison
Madison le 3 Juin 2023
I apologize I included the wrong code, but I changed it to pagetranspose and I get an error saying Matrix dimensions must agree.
dir = 'C:\Users\Madison-Riley\Desktop\Thesis\Copernicus Data\'; % change this path to your working directory
ncfile = 'Sea.Surface.Height.nc'; % name of data file from copernicus
ncdisp([dir,ncfile])
% Dimensions: [longitude = 121; latitude = 181; depth = 1; time = 25 ]
% time = ncread([dir,ncfile],'time');
lat = ncread([dir,ncfile],'latitude');
lon = ncread([dir,ncfile],'longitude');
SWH = ncread([dir,ncfile],'VHM0');
% plot wind:
clf
pcolor(lon,lat,pagetranspose(SWH));
shading flat;
colorbar

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Juin 2023
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

Plus de réponses (1)

Hiro Yoshino
Hiro Yoshino le 3 Juin 2023
I could reproduce the same error message as follows:
X = rand(3,3,4)
X =
X(:,:,1) = 0.6706 0.0303 0.5018 0.0730 0.1938 0.2540 0.8822 0.3482 0.4408 X(:,:,2) = 0.4965 0.3385 0.5116 0.1462 0.7965 0.0287 0.5615 0.5188 0.1173 X(:,:,3) = 0.8568 0.4259 0.6431 0.0039 0.5149 0.5037 0.5629 0.4344 0.3892 X(:,:,4) = 0.6134 0.9156 0.9039 0.1609 0.5476 0.5949 0.7602 0.2534 0.4676
transpose(X)
Error using .'
TRANSPOSE does not support N-D arrays. Use PAGETRANSPOSE/PAGECTRANSPOSE to transpose pages or PERMUTE to reorder dimensions of N-D arrays.
The best bet is replace this with pagetranspose as it says:
pagetranspose(X)
ans =
ans(:,:,1) = 0.2020 0.8862 0.2749 0.8334 0.3553 0.0783 0.6238 0.4919 0.9753 ans(:,:,2) = 0.7364 0.8973 0.6622 0.7870 0.0131 0.8621 0.1376 0.8198 0.8603 ans(:,:,3) = 0.1506 0.9980 0.8282 0.7839 0.0601 0.6889 0.4893 0.2768 0.0390 ans(:,:,4) = 0.8224 0.1869 0.4129 0.7513 0.9507 0.7576 0.9339 0.7996 0.8677
  3 commentaires
Cris LaPierre
Cris LaPierre le 3 Juin 2023
Modifié(e) : Cris LaPierre le 3 Juin 2023
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.
Madison
Madison le 3 Juin 2023
Error using '
TRANSPOSE does not support N-D arrays. Use PAGETRANSPOSE/PAGECTRANSPOSE to transpose pages or
PERMUTE to reorder dimensions of N-D arrays.
Error in view_wave_data (line 17)
pcolor(lon,lat,SWH');

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by