How do I use the for loop to replace elements in an array?
조회 수: 13 (최근 30일)
이전 댓글 표시
My array doesn't have any requirements.
댓글 수: 0
답변 (1개)
Voss
2022년 4월 12일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!