Subscript indices must either be real positive integers or logicals.

3 Ansichten (letzte 30 Tage)
MAT NIZAM UTI
MAT NIZAM UTI am 29 Mär. 2023
Beantwortet: Image Analyst am 29 Mär. 2023
Hi I tried to run this coding, but always getting error which is subscripts indices must either be real positive integers or logicals.
Here is my coding, I also attach the file starting from Data1 line.
clear all
clc
ncfile = 'filename.nc' ; % nc file name
% To get information about the nc file
ncinfo(ncfile)
% % to display nc file
ncdisp(ncfile)
% % to read a vriable 'var' exisiting in nc file
SSS = ncread(ncfile,'SSS_corr') ;
Lat = ncread(ncfile, 'Latitude');
Lon = ncread(ncfile, 'Longitude');
% SSS1 = SSS(1:end);
% Lat1 = Lat (1:end);
% Lon1 = Lon (1:end);
Data = [Lat(:),Lon(:),SSS(:)];
id = (Lat>=0&Lat<=14);
Data1 = Data(id,:,:);
X = Data1(:,1);
Y = Data1(:,2);
Z = Data1(:,3);
Lat1 = X;
Lon1 = Y;
SSS1 = Z;
n = length(Lat1);
minlat = 1;
maxlat = 14;
minlon = 95;
maxlon = 126;
% gridsize = 0.125;
[XX,YY] = meshgrid(linspace(minlat(Lat1),maxlat(Lat1),n),linspace(minlon(Lon1),maxlon(Lon1),n));
zz = surfergriddata(X,Y,Z,XX,YY, 'kriging')
Here is the error
Subscript indices must either be real positive integers or logicals.
Error in Copy_of_SMOS_nc (line 36)
[XX,YY] = meshgrid(linspace(minlat(Lat1),maxlat(Lat1),n),linspace(minlon(Lon1),maxlon(Lon1),n));

Antworten (2)

VBBV
VBBV am 29 Mär. 2023
Bearbeitet: VBBV am 29 Mär. 2023
[XX,YY] = meshgrid(linspace((Lat1(minlat),(Lat1(maxlat),n),linspace((Lon1(minlon)),(Lon1(maxlon),n))
  2 Kommentare
VBBV
VBBV am 29 Mär. 2023
Bearbeitet: VBBV am 29 Mär. 2023
Use the linspace command this way for Meshgrid command.
VBBV
VBBV am 29 Mär. 2023
Bearbeitet: VBBV am 29 Mär. 2023
% search the minlat , maxlat minlon & maxlon in the Arrays Lat1, Lon1 and
% input to linspace,meshgrid commands if thats what you actually need
LaMi = Lat1(Lat1 == minlat);
LaMa = Lat1(Lat1 == maxlat);
LoMi = Lon1(Lon1 == minlon);
LoMa = Lon1(Lon1 == maxlon);
[XX,YY] = meshgrid(linspace(Lat1(LaMi(1)),Lat1(LaMa(1)),n),linspace(Lon1(LoMi(1)),Lon1(LoMa(1)),n))

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 29 Mär. 2023

Kategorien

Mehr zu Special Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by