Error: Row index exceeds table dimensions.

3 views (last 30 days)
Salma fathi
Salma fathi on 16 Jun 2022
Answered: Peter Perkins on 16 Jun 2022
Hello, I am stuck at some point with this error . I am attaching a small sample of the file that contains the table SOLARL that is used in the code below, I am unable to attach all of it since it has a huge size.
The error accur when the loop index ii=5788 but before that it runs fine. And the length of the table 'dates' is 16590.
%data is stored in the table SOLARL
SOLARL.Date2 = datenum(SOLARL.Date);
%finding the unique dates that are in the table SOLARL
dates = unique(SOLARL.Date2);
PeakTable=[];
for ii = 1:length(dates)
fprintf('.......... table - %d of %d\n',ii, length(dates));
%iteratively, the data of each unique day is stored in the table tDate to be processed
tDate = SOLARL(SOLARL.Date2 == dates(ii), :);
tDate.Date2 = [];
tDate.Date = [];
%this loop will go through the table tDate and find the peak point
%according to a certain craiteria.
EDP=table2array(tDate);
for ied=1:length(EDP)
imax=[];
[~,imax] = max(EDP(:,7));
if (EDP(imax,6) < 190 || EDP(imax,6) >400)
EDP(imax,:)=[];
elseif ( EDP(imax,6) > 190 && EDP(imax,6) < 190)
break;
end
end
b=imax;
y=tDate.GDALT;
%To find the indices of the data rows of the points that are above and below the peak point
peak_y = tDate.GDALT(b) ;
idxl = y < peak_y ;
idxh = y > peak_y ;
numOfPointsL= length(y(idxl));
numOfPointsH= length(y(idxh));
%according to how many points there are, we extract only 20% of them
ExtractedNumPointsL=int8(0.2*numOfPointsL);
ExtractedNumPointsH=int8(0.2*numOfPointsH);
%the table pt will have the extracted rows that are above and below the
%peak point and the peak point stored in it.
pt=tDate(b-ExtractedNumPointsL: b+ExtractedNumPointsH,:); % here is the error
PeakTable=[PeakTable; pt];
end
  2 Comments
MJFcoNaN
MJFcoNaN on 16 Jun 2022
Hello,
Please post the whole error information from matlab.
Salma fathi
Salma fathi on 16 Jun 2022
this is the only message I am getting
Error using PeakConstruction (line 172)
Row index exceeds table dimensions.

Sign in to comment.

Answers (1)

Peter Perkins
Peter Perkins on 16 Jun 2022
SOLARL.Date2 = datenum(SOLARL.Date);
DON'T do that. Just use datetime. You can call unique, length, and == a on datetime vector.
Also, it appears that your outer loop can just be a grouped (by day) calculation using, probably, rowfun, or maybe groupsummary. Pretty hard to follow your code, so not sure exactly what that would look like.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!