Problem to delete rows in my matrix
显示 更早的评论
Hi, I am a beginner in matlab and I try to delete rows from my matrix when two following values in my 3rd column are the same. I tried this :
for q=1:length(res)-1
if res(q,3)==res(q+1,3)
res(q,:) = [];
end
end
But I have the error message :
Index exceeds matrix dimensions.
Error in trackthebeads (line 8)
if res(q,3)==res(q+1,3)
I had 4020 values at the beginning, it managed to delete 36 but then it blocked I don't know why. Can you help me? Thanks, Aude
3 个评论
per isakson
2016-11-21
and try
for q = length(res)-1 : -1 : 1
if res(q,3)==res(q+1,3)
res(q,:) = [];
end
end
Roger Stafford
2016-11-21
编辑:Roger Stafford
2016-11-21
@Per. I think this method might have the difficulty that a row might be deleted which might have provided a match in column 3 on the next step down, and that would abort another valid deletion. That is to say, there might be three successive equal elements in column 3 but only one row deletion as a result instead of two.
@Per Correction: On second thought I think your revised method actually does work properly. Forget the above paragraph.
Aude Rapet
2016-11-21
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Job and Task Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!