Subscript indices must either be real positive integers or logicals.

조회 수: 3 (최근 30일)
MAT NIZAM UTI
MAT NIZAM UTI 2023년 3월 29일
답변: Image Analyst 2023년 3월 29일
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));

답변 (2개)

VBBV
VBBV 2023년 3월 29일
편집: VBBV 2023년 3월 29일
[XX,YY] = meshgrid(linspace((Lat1(minlat),(Lat1(maxlat),n),linspace((Lon1(minlon)),(Lon1(maxlon),n))
  댓글 수: 2
VBBV
VBBV 2023년 3월 29일
편집: VBBV 2023년 3월 29일
Use the linspace command this way for Meshgrid command.
VBBV
VBBV 2023년 3월 29일
편집: VBBV 2023년 3월 29일
% 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))

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2023년 3월 29일

카테고리

Help CenterFile Exchange에서 Special Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by