Remake this without a loop
조회 수: 1 (최근 30일)
이전 댓글 표시
How to rewrite this without using a loop?
Basically I want to replace elements in matrix A with 0, that are equal to any of element in vector "vector"
vector = [A(A >= 1.5)].' % Vector, don't change.
for i = 1:vector
A(A == vector(i)) = 0;
end
댓글 수: 0
채택된 답변
the cyclist
2021년 10월 17일
% Pretend data
A = 1 : 7;
vector = [2 3 5];
% Replace values of A with 0, if they are in vector
A(ismember(A,vector)) = 0
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!