Error: Row index exceeds table dimensions.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1034890/image.png)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!