For loop with a 10000x6
显示 更早的评论
I have a 10000x6 matrix and i need to starters make a for loop which goes through the first column (it has values 1 and 0 in it) and deletes the rows with '0'. I've been battling with this as I just can't get it to work. If you could help with the whole loop.
1 个评论
Matt J
2018-1-3
When you say a "table", do you mean an actual table data type, or do you just mean a 10000x6 matrix, A?
回答(2 个)
Andrei Bobrov
2018-1-3
编辑:Andrei Bobrov
2018-1-3
Let T - your table:
T_out = T(T{:,1} ~= 0,:);
3 个评论
Matt J
2018-1-3
It is usually more efficient to keep the wanted data.
Is it?
@Matt J: It was something that I remember from doing some tests a few years ago, so quite likely depends on the number of elements and probably the MATLAB version. Some test results just now (test script is attached):
Elapsed time is 4.978532 seconds. % removing elements
Elapsed time is 1.840707 seconds. % keeping elements
A(A(:,1)==0,:)=[] ;
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!