Error: Row index exceeds table dimensions.

조회 수: 2(최근 30일)
Salma fathi
Salma fathi 2022년 6월 16일
답변: Peter Perkins 2022년 6월 16일
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);
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.
for ied=1:length(EDP)
[~,imax] = max(EDP(:,7));
if (EDP(imax,6) < 190 || EDP(imax,6) >400)
elseif ( EDP(imax,6) > 190 && EDP(imax,6) < 190)
%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
%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];
  댓글 수: 2
Salma fathi
Salma fathi 2022년 6월 16일
this is the only message I am getting
Error using PeakConstruction (line 172)
Row index exceeds table dimensions.

댓글을 달려면 로그인하십시오.


Peter Perkins
Peter Perkins 2022년 6월 16일
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.




Community Treasure Hunt

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

Start Hunting!

Translated by