필터 지우기
필터 지우기

Hi. I have a two-dimensional array Z of size 10x15, and two vectors, A = [1 2 4] and B = [3 2 1]. Using A and B, I want to access the following elements in Z: Z(1,3), Z(2,2), Z(4,1) only

조회 수: 3 (최근 30일)
Hi. I have a two-dimensional array Z of size 10x15, and two vectors, A = [1 2 4] and B = [3 2 1]. Using A and B, I want to access the following elements in Z: Z(1,3), Z(2,2), Z(4,1) only. I tried using Z(A,B) but this will give me all combinations of elements (i.e. Z(1,3), Z(1,2), Z(1,1), Z(2,3), ...). Any idea how to do this.

채택된 답변

Stefano Francavilla
Stefano Francavilla 2017년 11월 21일
편집: Stefano Francavilla 2017년 11월 21일
I think you get a submatrix where the elements you are looking for are in the main diagonal: use diag(Z(A,B))

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2017년 11월 21일
out = Z(sub2ind(size(Z),A,B))

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by