Centre of a matrix

1 次查看(过去 30 天)
Assume that have a matrix of the form :
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 4 5 6 7 1 2 0 0
0 0 2 0 0 0 3 8 0 0
0 0 4 0 0 0 7 6 0 0
0 0 4 5 7 5 8 5 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
And I want to get the centre of, in this case, small matrix inside the big matrix consisting of only 0s ( 2x3 in this case ). Can I write the function that would do it for me ? Thanks.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2017-7-4
编辑:Andrei Bobrov 2017-7-4
A = [0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 4 5 6 7 1 2 0 0
0 0 2 0 0 0 3 8 0 0
0 0 4 0 0 0 7 6 0 0
0 0 4 5 7 5 8 5 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0];
out = A(any(A,2),any(A));
out = out(~all(out,2),~all(out));
or
t = bwlabel(~A);
t = max(t(:)) == t;
out = A(any(t,2),any(t));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by