I am running into an issue as I am deleting rows in a matrix. As I delete rows, size(Matrix,1) changes, and I assume that is causing an error in the for statement. The error I receive is "Index exceeds matrix dimensions." Below is my first of two attempts at the code:
[~, ~, Matrix]=xlsread('TestEachSceneOnce.xls', 'Sheet1')for m = 1:size(Matrix,1) for n=1:size(Matrix,1) if strcmp(Matrix(m,4),Matrix(n,4)) & Matrix{n,5}~='alreadydone' & m~=n % without m~=n, we would be checking if a cell is equal to itself
Matrix{n,5}='alreadydone' Matrix(m,:)=[] else end end endxlswrite('TestEachSceneOnce.xls', Matrix, 'Sheet2')
Therefore, I tried to update size(Matrix,1) each time a row is deleted in the code below. I still get the following error: "Index exceeds matrix dimensions."
[~, ~, Matrix]=xlsread('TestEachSceneOnce.xls', 'Sheet1')UpdatedSizeOfMatrix=size(Matrix,1)for m = 1:UpdatedSizeOfMatrix for n=1:UpdatedSizeOfMatrix if strcmp(Matrix(m,4),Matrix(n,4)) & Matrix{n,5}~='alreadydone' & m~=n % without m~=n, we would be checking if a cell is equal to itself Matrix{n,5}='alreadydone' Matrix(m,:)=[] UpdatedSizeOfMatrix=size(Matrix,1) else end UpdatedSizeOfMatrix=size(Matrix,1) end end xlswrite('TestEachSceneOnce.xls', Matrix, 'Sheet2')
I would appreciate any help you can provide.
Best Answer