mex file giving wrong outputs
显示 更早的评论
Hi, I am generating a mex file for my State Space equation and running it on GPU. When I am running the mex file, I am getting different outputs than expected.
My State Space Equation is:
function out = stateequation(a,b,c,d,x,u) %#codegen
n = size(u,2);
coder.gpu.kernel()
for i = 1:n
x(:,i+1) = a*x(:,i)+ b*u(:,i); %% State Equation
end
out = c*x(:,1:n)+ d*u(:,1:n); %% Output equation
end
On running this code, I am getting answer as :
24 156 948
24 156 948
24 156 948
I have generated mex file using codegen method as follows:
A = double(zeros(3,3));
B = double(zeros(3,3));
C = double(zeros(3,3));
D = double(zeros(3,3));
X = double(zeros(3,1));
U = double(zeros(3,3));
cfg = coder.gpuConfig('mex');
codegen -args {A,B,C,D,X,U} -config cfg stateequation
But on running this mex file I am getting result as :
156 156 156
156 156 156
156 156 156
Why it is giving different answer? Can Someone help me with this?
Thank you in advance
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!