how can i create only the Matrix index

조회 수: 1 (최근 30일)
mohammed hussein
mohammed hussein 2017년 11월 7일
댓글: mohammed hussein 2017년 11월 7일
Hi i would like to create two variable that represent the matrix index of any size of matrix for example if i have matrix
A=[(1,1) (1,2) (1,3);(2,1) (2,2) (2,3);(3,1) (3,2) (3,3)]
how can i create like the matrix A
thank you

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 7일
The easiest way is
sparse(list_of_row_indices, list_of_corresponding_column_indices, list_of_corresponding_values)
You can full() the result afterwards.
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 11월 7일
[R,C] = ndgrid(1:size(YourMatrix,1), 1:size(YourMatrix,2));
A = idxMatrix = arrayfun(@(r,c) [r,c], R, C, 'uniform', 0);
mohammed hussein
mohammed hussein 2017년 11월 7일
thank you very much , it works perfectly

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

추가 답변 (0개)

카테고리

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