replacing values in a vector with new value?

14 visualizaciones (últimos 30 días)
Leslie Paul
Leslie Paul el 27 de Ag. de 2016
Comentada: Azzi Abdelmalek el 27 de Ag. de 2016
Basically, I have a large vector and want to add 180 to all the negative values and subtract 180 to all positive values in the vector. Finally, I should have the same size vector with the changes. Appreciate a helping hand

Respuestas (2)

James Tursa
James Tursa el 27 de Ag. de 2016
Editada: James Tursa el 27 de Ag. de 2016
v = your vector
n = v < 0; % the negative indexes (logical)
p = v > 0; % the positive indexes (logical)
v(n) = v(n) + 180;
v(p) = v(p) - 180;
Note: This doesn't change any exact 0 values, per your description.

Image Analyst
Image Analyst el 27 de Ag. de 2016
Try this:
v = v - sign(v) * 180
where v is your vector. It will do what you asked for.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by