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 Kommentar

Matt J
Matt J am 3 Jan. 2018
When you say a "table", do you mean an actual table data type, or do you just mean a 10000x6 matrix, A?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Andrei Bobrov
Andrei Bobrov am 3 Jan. 2018
Bearbeitet: Andrei Bobrov am 3 Jan. 2018

1 Stimme

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

3 Kommentare

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

Melden Sie sich an, um zu kommentieren.

Matt J
Matt J am 3 Jan. 2018
Bearbeitet: Matt J am 3 Jan. 2018

1 Stimme

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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Jan. 2018

Bearbeitet:

am 6 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by