Error creating matlab pcolor

2 次查看(过去 30 天)
Madison
Madison 2023-7-23
回答: Voss 2023-7-23
I am running into an error plotting temperature form my file (it contains data from Jan-March)
close all, clear all clc
% note I've renamed the files, call them what you like but they need to
% have the year in them to load in a loop
fp = 'C:\Users\Madison-Riley\Desktop\Thesis\Environmental_Data\Temperature';
ncdisp(fullfile(fp,'Temp_Q1(2020).nc'))
%look at one file to interrogate and understand dimensions and variables
% test=ncread([filepath,'June2021.nc'],'uo'); whos test
time = ncread(fullfile(fp,'Temp_Q1(2020).nc'),'time'); whos time
ntime=length(time);
lon=ncread(fullfile(fp,'Temp_Q1(2020).nc'),'longitude');
lat=ncread(fullfile(fp,'Temp_Q1(2020).nc'),'latitude');
[LON,LAT]=meshgrid(lon,lat);
bottomT=ncread(fullfile(fp,'Temp_Q1(2020).nc'),'bottomT'); whos utide
% dimensions lon*lat*depth*time
% https://uk.mathworks.com/help/matlab/ref/ncread.html
% try different depth layers here, why is the land extent so different?
bottomTtest=ncread(fullfile(fp,'Temp_Q1(2020).nc'),'bottomT',[1 1 1],[length(lon) length(lat) 1 1]);
close all
pcolor(LON,LAT,bottomT.'), shading flat, colorbar
I get the following Error:
Error using internal.matlab.imagesci.nc/read
COUNT has incorrect number of elements (4). The variable has 3 dimensions.
Error in ncread (line 76)
vardata = ncObj.read(varName, varargin{:});
Error in Temp_Q1_20 (line 22)
bottomTtest=ncread(fullfile(fp,'Temp_Q1(2020).nc'),'bottomT',[1 1 1],[length(lon) length(lat) 1 1]);

采纳的回答

Voss
Voss 2023-7-23
The error message indicates that the error is generated by this line:
bottomTtest=ncread(fullfile(fp,'Temp_Q1(2020).nc'),'bottomT',[1 1 1],[length(lon) length(lat) 1 1]);
The error is due to the fact that you've specified 3 start values but 4 count values
bottomTtest=ncread(fullfile(fp,'Temp_Q1(2020).nc'),'bottomT',[1 1 1],[length(lon) length(lat) 1 1]);
% ^^^^^^^ 3 starts
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 counts
just like the error message says: "COUNT has incorrect number of elements (4). The variable has 3 dimensions."

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

标签

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by