考虑以下MATLAB函数,
function m = gen_4_points()
a = gen_const()% integer
b = gen_const()% integer
[x1 y1] = gen_start_point(a, b)% real
[x2 y2] = gen_start_point(a, b)% real
[x3 y3] = gen_start_point(a, b)% real
[x4 y4] = gen_start_point(a, b)% real
%r(1:4, 1:4) = 0;
r = [ a b x1 y1 ;%int int real real
a b x2 y2 ;%int int real real
a b x3 y3 ;%int int real real
a b x4 y4 %int int real real
];
m = r;
end
结果矩阵不是我想要的矩阵。
矢量值没问题。
但是,结果矩阵具有所有整数值。
>> m = gen_4_points(); a = 0 b = -2 x1 = -0.6766 y1 = -2.3028 x2 = -0.9189 y2 = -3.2118 x3 = 1.2869 y3 = -2.2803 x4 = 1.5511 y4 = -2.4353 >> m m = 0 -2 -1 -2 0 -2 -1 -3 0 -2 1 -2 0 -2 2 -2 >>
真的发生了什么?
如何解决问题?
答案 0 :(得分:2)
Typecast a
和b
加倍:
a = double(gen_const())
b = double(gen_const())