필터 지우기
필터 지우기

Error creating matlab pcolor

조회 수: 1 (최근 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에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by