how to sutract specific elements in a long array?

조회 수: 1(최근 30일)
friet 2017년 10월 1일
편집: OCDER 2017년 10월 1일
Hi Suppose I have
x=[ -0.401993355481728
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.
Thanks a lot

채택된 답변

OCDER 2017년 10월 1일
편집: OCDER 2017년 10월 1일
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;

추가 답변(0개)


Find more on Matrices and Arrays in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by