Matrix and array indices

1 次查看(过去 30 天)
Hi all,
I try ti run a loop as described below. However I keep having the same error and I dont understand where it comes from (see below).
Can someone help please?
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in read_NC_create_data (line 37) M(i,1) = M(i,1) + u10(j,k,i+delaytime);
close all
clear all
clc
cd ('D:\SEEC\Matt\');
% Era5 folder:
filename = 'june_wind.nc';
% Files in the folder:
ncTime = ncread(filename,'time');
ncLon = ncread(filename,'longitude');
ncLat = ncread(filename,'latitude');
u10 = ncread(filename,'u10');
v10 = ncread(filename,'v10');
% date number into date calendar:
ncDate = datetime(1900,1,1,'Format','dd/MM/yyyy HH:mm:ss') + hours(ncTime);
% n rows according to the number of timesteps from drifter data;
% m columns for data to extract
M = zeros(566,2);
N = xlsread('REEF_for_Matt.xlsx'); % Matrix to compare and select correct data.
N_Lon = N (:,3);
N_Lat = N(:,4);
% n-1 Start of periof of interest:
delaytime = 130;
for i = 1:566 % length number timestep drifter
clear j k
j = N_Lon(i,1);
k = N_Lat(i,1);
M(i,1) = M(i,1) + u10(j,k,i+delaytime);
end

采纳的回答

Matt J
Matt J 2021-8-10
Presumably your N_Lon and N_Lat values are not positive integers.
  2 个评论
Jonathan Demmer
Jonathan Demmer 2021-8-11
I checked yesterday and yes it was the problem... thank you for the answer.
Matt J
Matt J 2021-8-11
you're welcome, but please Accept-click the answer to indicate that your problem is resolved.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by