Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Make true all the false rows of a column of a matrix which are in between the first true and the last true row

Asked by Giorgos Papakonstantinou

Giorgos Papakonstantinou

on 16 Jun 2013
Accepted Answer by Andrei Bobrov

Andrei Bobrov

The first true element of column 1 of matrix a is at row 2. The last true element of column 1 of matrix a is at row 9. I want to get a matrix b whose 1st column will start with false, from row 2 to row 9 will b true and row 10 will be false. Likewise, I want to do the same for the rest of the columns of matrix a.

Example:

a =[
       0     0     1     0
       1     0     0     0
       1     0     0     1
       1     0     0     1
       1     1     1     0
       0     0     0     1
       1     1     1     0
       0     1     1     0
       1     0     0     0
       0     0     0     1];
b =[
       0     0     1     0
       1     0     1     0
       1     0     1     1
       1     0     1     1
       1     1     1     1
       1     1     1     1
       1     1     1     1
       1     1     1     1
       1     0     0     1
       0     0     0     1];

0 Comments

Giorgos Papakonstantinou

Giorgos Papakonstantinou

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov

Andrei Bobrov

on 16 Jun 2013
Accepted answer
b = cumsum(a)&flipud(cumsum(flipud(a)))

1 Comment

Giorgos Papakonstantinou

Giorgos Papakonstantinou

on 16 Jun 2013

I am impressed! I must thank you!

Andrei Bobrov

Andrei Bobrov

Contact us