Replacing all even numbers in my matrix with their square root value
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Cy'an Tebo
am 15 Mär. 2021
Beantwortet: KSSV
am 15 Mär. 2021
So I put in the code :
A=[1 4 9; 8 16 7; 3 36 4]
X=sqrt(A(rem(A,2)==0))
It did square root each even number but it put it in it's own matrix but I was trying to replace the even number with new values while still having all the other values in the matric still. How do I fix this?
0 Kommentare
Akzeptierte Antwort
Mohammad Sami
am 15 Mär. 2021
You need to assign it back to A to replace the even values.
A=[1 4 9; 8 16 7; 3 36 4];
i = rem(A,2)==0;
A(i) =sqrt(A(i))
0 Kommentare
Weitere Antworten (1)
KSSV
am 15 Mär. 2021
A=[1 4 9; 8 16 7; 3 36 4]
idx = mod(A,2) ;
A(idx==0) = sqrt(A(idx==0))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB 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!