필터 지우기
필터 지우기

How to replace all but one value with zero

조회 수: 9 (최근 30일)
Hylke Dijkstra
Hylke Dijkstra 2022년 1월 3일
댓글: Hylke Dijkstra 2022년 1월 3일
I have generated the following vector f:
f=[49; 18; 48]
And I want to be able to replace each element, except let's say f21, with a value, let's say zero.
f=[0; 18; 0]
I have been playing around with loops, but I cant seem to figure it out just yet..
Does anyone have any advice on how to handle this? Preferably a solution that also works for larger matrices.
Best

채택된 답변

KSSV
KSSV 2022년 1월 3일
f=[49; 18; 48] ;
f(f~=18) = 0 ; % repalce by value
f=[49; 18; 48]
iwant = zeros(size(f)) ;
iwant(3) = f(3) ; % replace by index

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by