Row index exceeds table dimensions.

22 views (last 30 days)
Youcef Kara
Youcef Kara on 2 Apr 2020
Answered: Tommy on 2 Apr 2020
trans=readtable('csv71106.csv');
trans.Properties.VariableNames={'Date','Name','Amount'};
clearvars -except trans,clc;
for k=1:height(trans);
if table2array(trans(k,3))>0;
trans(k,:)=[];
else
continue
end
end
I'm trying to get rid of the positive values in the table ''trans'' with a for loop. Thank you.

Accepted Answer

Tommy
Tommy on 2 Apr 2020
This line:
trans(k,:)=[];
shortens your table trans, but k will keep increasing until it reaches the original height of trans, meaning k will eventually surpass the current height of trans and cause the error.
I believe simply
trans=readtable('csv71106.csv');
trans.Properties.VariableNames={'Date','Name','Amount'};
trans(trans.Amount > 0, :) = [];
should work.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!