How do I use the for loop to replace elements in an array?
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
My array doesn't have any requirements.
0 Commenti
Risposte (1)
Voss
il 12 Apr 2022
array = randi(7,1,20);
disp(array);
% use a for loop to replace all the 4's in array with 19's:
for ii = 1:numel(array)
if array(ii) == 4
array(ii) = 19;
end
end
disp(array);
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!