Hello,
If a have a Matrix M and I want to create a new one, call it Central_M, which should be the central part of M and of a defined size s, how can I do it?
M_central = ?
Thanks in advance for your reply.

댓글 수: 2

Chris McComb
Chris McComb 2015년 2월 24일
What exactly do you mean by 'central'? And can you define s?
Auryn_
Auryn_ 2015년 2월 25일
Central means that I want to take only the central part of the matrix of a defined size s. s = imcrop(I,[max(1,i-10) max(1,j-10) 23 23]);

댓글을 달려면 로그인하십시오.

답변 (2개)

Jos (10584)
Jos (10584) 2015년 2월 25일

1 개 추천

Something like this?
M = spiral(10) % test matrix
S = 2 % s elements around the central position
% the resulting matrix will be 2*S+1 squared in size
dx = -S:S ;
RC0 = ceil(size(M)/2) % central position
OUT = M(RC0(1)+dx, RC0(2)+dx)
RAGHAVENDRA
RAGHAVENDRA 2015년 2월 25일
편집: Guillaume 2015년 2월 25일

0 개 추천

M_central=M(floor(size(M,1)/2)-floor(s/2):floor(size(M,1)/2)+floor(s/2),floor(size(M,2)/2)-floor(s/2):floor(size(M,2)/2)+floor(s/2));
The above instruction will work, you can use 'round' instead of 'floor' to change the matrix indices accordingly.

댓글 수: 3

Guillaume
Guillaume 2015년 2월 25일
Please use the {} Code button to format code in your answer
Auryn_
Auryn_ 2015년 2월 25일
I receive an error message :(
RAGHAVENDRA
RAGHAVENDRA 2015년 2월 25일
편집: RAGHAVENDRA 2015년 2월 25일
It is working perfectly for me, this is the example that i have tried
M=randi(5,[10 10]);
s=2;
M_central=M(floor(size(M,1)/2)-floor(s/2):floor(size(M,1)/2)+floor(s/2),floor(size(M,2)/2)-floor(s/2):floor(size(M,2)/2)+floor(s/2))
What is the error message?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2015년 2월 24일

댓글:

2015년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by