Wrong results from Matlab Function in Real Time

1 view (last 30 days)
Hello, I'm using "MATLAB Function" (the one that generates code) in a real-time environment model(Quarc). The output of the function though doesn't match the correct output. i.e it's not what it should be. The function is shown at the bottom. If I run the function manually with an input of 1100 for example my output should be a 5x1 element = [65 65 4 76 4]. However in real-time execution I get [65 65 137 128 4]. Why? How can I fix this?
Best regards, Remus
function y = fcn(u)
%#codegen
M_prewrap = u;
M = M_prewrap;
message = [0 0 0 0 0];
message(1) = 65;
message(2) = 65;
check_sum = 0;
i=1;
%for i=1:length(u)
M_binary = dec2bin(M,16);
byte1 = bin2dec(M_binary(1:8));
byte2 = bin2dec(M_binary(9:16));
message(2*i+1) = byte1;
message(2*i+2) = byte2;
check_sum = check_sum + sum(M_binary=='1');
%end
message(end) = check_sum;
y = [message];

Answers (0)

Categories

Find more on Code Generation 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!