MATLAB: How to fix error index exceeds matrix dimensions. I am very new to matlab and am trying to write a loop for this data set but I keep getting this error. Any help would be appreciated!

errorloop

for i=1:length(Data);
for j=1:3
if Data(i,j)<=0
Data(i,:)=[];
end
end
end

Best Answer

You remove rows of Data, thus its size is shrinking during your loop. One way to resolve this is removing those rows after your loop:
idx=[];
for i=1:size(Data,1)
if any(Data(i,:)<=0)
idx=[idx,i];
end
end
Data(idx,:)=[];