Effacer les filtres
Effacer les filtres

Matrix and array indices

2 vues (au cours des 30 derniers jours)
Jonathan Demmer
Jonathan Demmer le 10 Août 2021
Commenté : Matt J le 11 Août 2021
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

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by