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?

 采纳的回答

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

更多回答(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

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by