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

1 Ansicht (letzte 30 Tage)
Olayinka
Olayinka am 19 Nov. 2023
Bearbeitet: madhan ravi am 19 Nov. 2023
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

Akzeptierte Antwort

Chunru
Chunru am 19 Nov. 2023
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

Weitere Antworten (1)

madhan ravi
madhan ravi am 19 Nov. 2023
A(a + (b-1)*size(A,1)) = 0
  1 Kommentar
madhan ravi
madhan ravi am 19 Nov. 2023
Bearbeitet: madhan ravi am 19 Nov. 2023
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by