how to multiply certain numbers in a matrice

3 Ansichten (letzte 30 Tage)
Apple
Apple am 8 Feb. 2017
Bearbeitet: Stephen23 am 8 Feb. 2017
if have a matrice A=[1,5,4;3,1,5;6,3,1] But I want to multiply only certain numbers for example A=[2,5,4;3,2,5;6,3,2] how do i do this.

Antworten (2)

Guillaume
Guillaume am 8 Feb. 2017
You haven't explain what certain numbers mean. At a guess:
A(A == 1) = A(A == 1) * 2;

Stephen23
Stephen23 am 8 Feb. 2017
Bearbeitet: Stephen23 am 8 Feb. 2017
"certain numbers" == numbers along the diagonal ?
>> A = [1,5,4;3,1,5;6,3,1]
A =
1 5 4
3 1 5
6 3 1
>> idx = 1==eye(3);
>> A(idx) = A(idx)*2
A =
2 5 4
3 2 5
6 3 2

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by