Select values from martix with an absolute value and set them to zero.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Benjamin Nienhouse
am 16 Okt. 2020
Kommentiert: Benjamin Nienhouse
am 16 Okt. 2020
So I'm having trouble with this, my goal is to select values from my random 6x6 matrix (ranging from [-10,10]) with an absolute value of 5 and set them equal to zero.
Any advice, I'm new to Matlab as of recently and don't know what I'm doing half the time.
0 Kommentare
Akzeptierte Antwort
Akira Agata
am 16 Okt. 2020
Like this?
A = randi([-10 10],6); % 6x6 matrix (ranging from [-10,10])
idx = abs(A) == 5; % Find elements whose absolute value == 5
A(idx) = 0; % Set them to 0
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices 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!