Search code examples
matlab

Index exceeds the number of array elements. Index must not exceed 631988


I got error

"Index exceeds the number of array elements. Index must not exceed 631988"

When try to find the problem I notice that it belong to index is like over 631988 even the empty row in table is after 631988 as shown in attached screenshot

table

The error is related to this line in code becouse I put index to 1000000 so how can make it depend on index of table

Data='tabledata.txt';
[Arrivals]=importdata(Data);
Arrivalsdata=Arrivals(:,1);

for i=2:1000000
 Interarrivalptk(i-1)=Arrivalsdata(i)-Arrivalsdata(i-1);
end

Solution

  • The way I see it you want to only loop over the Arrivalsdata array. Something like this:

    Data='tabledata.txt';
    [Arrivals]=importdata(Data);
    Arrivalsdata=Arrivals(:,1);
    
    for i=2:length(Arrivalsdata)
     Interarrivalptk(i-1)=Arrivalsdata(i)-Arrivalsdata(i-1);
    end