Select elements of Matrix?

조회 수: 5 (최근 30일)
Fred John
Fred John 2014년 12월 3일
편집: Azzi Abdelmalek 2014년 12월 3일
Hi,
I have a 20x20 matrix, P. I wish to define a matrix Q such that the rows of Q are the LAST 18 rows of P (rows 2-20), and the columns of Q are the last 18 columns of P (columns 2-20).

채택된 답변

Guillaume
Guillaume 2014년 12월 3일
It's basic matrix indexing:
Q = P(2:20, 2:20)

추가 답변 (2개)

C.J. Harris
C.J. Harris 2014년 12월 3일
Like so:
P = magic(20);
Q = P(end-17:end,end-17:end);
Or this, as I assume you mean rows/columns 3 to 20 - otherwise you'll have 19 rows/columns:
P = magic(20);
Q = P(3:20,3:20);

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 3일
편집: Azzi Abdelmalek 2014년 12월 3일
P=rand(20) % Example
n=18
Q=P(end-n+1:end,end-n+1:end)

카테고리

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