Effacer les filtres
Effacer les filtres

how to sutract specific elements in a long array?

4 vues (au cours des 30 derniers jours)
friet
friet le 1 Oct 2017
Modifié(e) : OCDER le 1 Oct 2017
Hi Suppose I have
x=[ -0.401993355481728
-0.398671096345515
-0.395348837209302
-0.392026578073090
-0.388704318936877
-0.385382059800665
-0.382059800664452
-0.378737541528239
-0.375415282392027
-0.372093023255814
-0.368770764119601
-0.365448504983389
-0.362126245847176
-0.358803986710964
-0.355481727574751
-0.352159468438538
-0.348837209302326
-0.345514950166113
-0.342192691029900
-0.338870431893688];
I want to generate an array y which is the same as x except the elements in the middle lets say x(7) to x(11) are subtracted by some constant number.
y(7:11)=x(7:11)-0.5;
Thanks a lot
GH

Réponse acceptée

OCDER
OCDER le 1 Oct 2017
Modifié(e) : OCDER le 1 Oct 2017
y = x; %make copy of x
y(7:11) = x(7:11)-0.5; %you had it right
%Or, you could do this. same thing:
y(7:11) = y(7:11)-0.5;
%For a different range of values (Idx) and to subtract a constant (C), you could do:
Idx = 7:11;
C = 0.5;
y(idx) = y(idx) - C;

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by