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

1 次查看(过去 30 天)
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];

采纳的回答

Andrei Bobrov
Andrei Bobrov 2013-6-16
b = cumsum(a)&flipud(cumsum(flipud(a)))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by