Borrar filtros
Borrar filtros

How to replace all but one value with zero

9 visualizaciones (últimos 30 días)
Hylke Dijkstra
Hylke Dijkstra el 3 de En. de 2022
Comentada: Hylke Dijkstra el 3 de En. de 2022
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

Respuesta aceptada

KSSV
KSSV el 3 de En. de 2022
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

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by