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
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
Andrei Bobrov 2018년 1월 3일
편집: Andrei Bobrov 2018년 1월 3일

1 개 추천

Let T - your table:
T_out = T(T{:,1} ~= 0,:);

댓글 수: 3

Stephen23
Stephen23 2018년 1월 3일
편집: Stephen23 2018년 1월 3일
+1 It is usually more efficient to keep the wanted data.
Matt J
Matt J 2018년 1월 3일
It is usually more efficient to keep the wanted data.
Is it?
Stephen23
Stephen23 2018년 1월 3일
편집: Stephen23 2018년 1월 6일
@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

댓글을 달려면 로그인하십시오.

Matt J
Matt J 2018년 1월 3일
편집: Matt J 2018년 1월 3일

1 개 추천

A(A(:,1)==0,:)=[] ;

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 1월 3일

편집:

2018년 1월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by