From: fraser5002 on
Hi i want to extract all non zero rows from a matrix how do i do this?

My Matrix has 5 cols and roughly 20 rows

a row will either have all 5 cols non zero or all 5 cols zeros .

How do i make a copy if the array only extracting the non zero rows to make for example a 2 x 5 matrix

Thanks
From: Jos (10584) on
fraser5002 <fraser.dickson(a)selexgalileo.com> wrote in message <1197132806.320576.1267777303691.JavaMail.root(a)gallium.mathforum.org>...
> Hi i want to extract all non zero rows from a matrix how do i do this?
>
> My Matrix has 5 cols and roughly 20 rows
>
> a row will either have all 5 cols non zero or all 5 cols zeros .
>
> How do i make a copy if the array only extracting the non zero rows to make for example a 2 x 5 matrix
>
> Thanks

Learn about logical indexing:

MyMatrix = [0 0 1 ; 0 0 0 ; 1 2 3 ; 0 0 0]
TF = MyMatrix==0
TFrow = ~all(TF,2)
MyMatrix(TFrow,:)

Jos