How do I form a matrix from an array of rows and columns

조회 수: 1 (최근 30일)
Olayinka
Olayinka 2023년 11월 19일
편집: madhan ravi 2023년 11월 19일
A=ones(10)
a=[1 3 5 6 9]
b=[1 2 4 7 9]
A(a,b)=0 should provide A(1,1)=0 A(3,2)=0 A(5,4)=0 A(6,7)=0 A(9,9)=0

채택된 답변

Chunru
Chunru 2023년 11월 19일
A=ones(10);
a=[1 3 5 6 9];
b=[1 2 4 7 9];
A(sub2ind(size(A), a,b)) = 0;
A
A = 10×10
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1

추가 답변 (1개)

madhan ravi
madhan ravi 2023년 11월 19일
A(a + (b-1)*size(A,1)) = 0
  댓글 수: 1
madhan ravi
madhan ravi 2023년 11월 19일
편집: madhan ravi 2023년 11월 19일
A=ones(10);
a=[1 3 5 6 9];
b=[1 2 4 7 9];
A(a + (b-1)*size(A,1)) = 0
A = 10×10
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1

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

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by