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 Center および File ExchangeSpecial Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by