开发者

Floating point problems in C and Matlab

Hey there, I have floating point problems in my matlab-mex file where I get values at the magnitude 10^(-12) to 10^(-13)... Is there an '开发者_如何学编程dirty' way to solve them to at least set those values to zero after the computation if they are so small? Thanks!


If it's an array, you could do something like:

small_inds = find(abs(array) < 10^-12);
array(small_inds) = zeros(length(small_inds),1);

(edited to add abs() for clarity—thanks nimrodm)


Not sure if this is what you're looking for (I guess the question is do you want this to be done in the mex file, or not), but my trick is to run a logic operations. Say the loaded mex matrix is X

Xm = abs(X) > max_error;
X = Xm .* X;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜