How do I replace Matrix elements
Mostra commenti meno recenti
Given a matrix A replace elements not equal 0 and not equal 1 by 5. Use disp() function to print out the resulting array.
So far I've got
A(A~=0) = 5;
disp(A);
but do not know how to make it 0 AND 1.
2 Commenti
KSSV
il 27 Ott 2020
When you use ~=0 and replace those with 5, the elements whch have 1 also will be eplaced by 5 right?
Liam Bouchereau
il 27 Ott 2020
Risposta accettata
Più risposte (1)
Use AND instead of OR:
>> A = [-1,0,4,6;1,1,0,2;-7,0,5,0;5,1,5,1]
A =
-1 0 4 6
1 1 0 2
-7 0 5 0
5 1 5 1
>> A(A~=0&A~=1) = 5
A =
5 0 5 5
1 1 0 5
5 0 5 0
5 1 5 1
Categorie
Scopri di più su Library Development in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!