mex file giving wrong outputs
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!