问题
If my input matrix is:
v =
-0.7071 0.5774 0.4082
0.0000 -0.5774 0.8165
0.7071 0.5774 0.4082
The output should be:
v =
-1 1 1
0 -1 2
1 1 1
回答1:
[A,B] = size(v)
for ii = 1:B
v(:,ii) = v(:,ii)./abs(min(v(:,ii)));
end
In case this is the exact example you have.
And just in case doubles are not good enough:
v = int32(v); % or whichever integer you want
bsxfun way, thanks to @rayryeng:
v = bsxfun(@rdivide, v, abs(min(v,1)));
来源:https://stackoverflow.com/questions/32076972/how-to-convert-decimals-in-a-matrix-to-integers