如何将矩阵中的小数转换为整数? [英] How to convert decimals in a matrix to integers?
本文介绍了如何将矩阵中的小数转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的输入矩阵是:
v =
-0.7071 0.5774 0.4082
0.0000 -0.5774 0.8165
0.7071 0.5774 0.4082
输出应为:
v =
-1 1 1
0 -1 2
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
方式,感谢@rayryeng:
bsxfun
way, thanks to @rayryeng:
v = bsxfun(@rdivide, v, abs(min(v,1)));
这篇关于如何将矩阵中的小数转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文