Select certain sub-matrix from matrix

Hi everyone, I have a matrix in such form that:
1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1 0
1 1 0 1 1 1 1 0 0 1
1 1 0 0 0 0 0 1 1 1
I would like to single out the sub-matrix enclosed (above zeros) by zero elements, and set them all to zero as well. I knew it can be done by a simple for loop, since I need to run it many times, I want to vectorize the process. Thanks in advanced for any help and suggestion.

4 件のコメント

Vaclav Rimal
Vaclav Rimal 2016 年 3 月 15 日
Playing go?
Thomas
Thomas 2016 年 3 月 15 日
No. I am dealing with surface evolution, but it looks just like Go :)
KSSV
KSSV 2016 年 3 月 16 日
編集済み: KSSV 2016 年 3 月 16 日
Question is not clear......can you tell me the sub matrix you are expecting from the given matrix? Better type the matrix.
Vaclav Rimal
Vaclav Rimal 2016 年 3 月 16 日
After your edit, the problem became more simple. What about this (suppose your original matrix is called a):
[m,pos]=min(a);
for i=1:size(a,2)
a(1:pos(i),i)=0;
end
However, I can't think of any way to avoid the for cycle. Probably indexing the matrix elements in the column-vector, one-index manner?

サインインしてコメントする。

回答 (1 件)

Guillaume
Guillaume 2016 年 3 月 16 日

1 投票

If all you want to do is propagate the zeros upward then a cumprod on the flipped up-down matrix is all that's needed:
a = [1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1 0
1 1 0 1 1 1 1 0 0 1
1 1 0 0 0 0 0 1 1 1];
flipud(cumprod(flipud(a)))

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2016 年 3 月 15 日

回答済み:

2016 年 3 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by