我在 Matlab 中有一个我定义的命令,它应该返回整数值:
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
我不想对结果进行四舍五入。我希望这些值从一开始就是int
。
这是我尝试过的:
x = int32([0 0 0 0 0 0 0 ])
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
%// but this is not working, and not giving integer values.
知道如何强制 x
为 int
值矩阵而不是 double
吗?
最佳答案
这是 documentation 中的 intcon
示例
:
Example:
intcon = [1,2,7]
meansx(1), x(2), and x(7)
take only integer values.
因此,如果您希望 x
的所有元素均为整数,则应将 intcon
设置为 1:numel(f)
。
关于arrays - 如何强制函数返回 int32 整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48478081/