MATLAB: Row index exceeds table dimensions.

row indextable

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.

Best Answer

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.