How can i scale certain values in a vector?

I have a certain vector with data and now i want to scale all values below 0 to values between -1 and 0 and all values above 0 i want to scale to values between 1 and 0.
So i have a vector A All the values below 0 (<0) i want to devide by a certain value all the values above 0 (>0) i want to devide to another certain value all the values which are 0 should stay 0.
Is this possible to do with matlab?

 Accepted Answer

See if this does what you want:
V = 2*randn(1,20); % Create Vector
VH = find(V >= 0); % Indices Of V >= 0
VL = find(V < 0); % Indices Of V < 0
VHScaled(VH) = V(VH)/max(V(VH)); % Scale & Map To Original Indices
VLScaled(VL) = -V(VL)/min(V(VL));
figure(1)
plot(V)
hold on
plot(VHScaled)
plot(VLScaled)
hold off
grid
grid

More Answers (1)

ix=x>0; % logical vector +ive loc's
x(ix)=x(ix)/max(x(ix)); % normalize +ive
x(~ix)=x(~ix)/max(abs(x(~ix))); % normalize -ive

Categories

Find more on MATLAB 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!