Filter löschen
Filter löschen

Error creating matlab pcolor

1 Ansicht (letzte 30 Tage)
Madison
Madison am 23 Jul. 2023
Beantwortet: Voss am 23 Jul. 2023
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]);

Akzeptierte Antwort

Voss
Voss am 23 Jul. 2023
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."

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by