I am working with a cell array. If there are any rows with the same value in column 4, I want to delete one of them. What I am thinking I could do is to replace the row with the repeated value in column 4 with all 0s. Then, I could write only rows that do NOT contain only 0s to a new table. Here is the code that replaces a row with 0s. It works.
[~, ~, 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' for p = 1:size(Matrix,2) % number of rows
Matrix{n,p}=0 end else end endendxlswrite('TestEachSceneOnce.xls', Matrix, 'Sheet2')
I am having trouble with this next part. When I try this:
t=readtable('TestEachSceneOnce.xls', 'Sheet', 'Sheet2', 'ReadVariableNames', false)for q = 1:size(Matrix,1) RowsOfZeros=(Matrix{q,1}==0) badrows=all(RowsOfZeros,2) t=t(~badrows,:)endwritetable(t, 'TestEachSceneOnce.xls', 'Sheet', 'Sheet3', 'WriteVariableNames', false)
I get this error:
Row index exceeds table dimensions.
When I try this
t=readtable('TestEachSceneOnce.xls', 'Sheet', 'Sheet2', 'ReadVariableNames', false)RowsOfZeros=all(Matrix,2)badrows=all(RowsOfZeros,2)t=t(~badrows,:)writetable(t, 'TestEachSceneOnce.xls', 'Sheet', 'Sheet3', 'WriteVariableNames', false)
I get this error:
Undefined function 'all' for input arguments of type 'cell'.
Is there any way to say "if all the cells in a given row of Matrix contain 0, don't include them in t"?
The spreadsheet I am working with is attached.
Best Answer