Subscript indices must either be real positive integers or logicals.
2 次查看(过去 30 天)
显示 更早的评论
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));
0 个评论
回答(2 个)
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
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))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!