0

I translated my MATLAB code to C++ using MATLAB Coder and I changed the main.cpp to create a executable. Everything seems ok until here, but when I print my predict output, my classname has an extra character. How can I solve this situation? Classes are virginica and versicolor. When I run my program in command line, output is something like this: versicolorÌ

What am I doing wrong?

MATLAB Entry-Function
function output_lab = testMod(input_data)

    Mod = loadCompactModel('model');
    output_lab = predict(Mod, input_data);

end
GENERATED CODE
int main(int argc, const char * const argv[])
{

  double input_data[4];
  cell_wrap_0 output_lab[1];

  for (int contador = 0; contador < 4; contador++)
  {
      input_data[contador] = atof(argv[contador + 1]);
      printf("%f ", input_data[contador]);
  }

  printf("\n");

  testMod_initialize();

  testMod( input_data, output_lab);

  cout << output_lab[0].f1.data;

  getchar();

  return 0;
}
3
  • 2
    Probably you are trying to display an array of characters which is not terminated by 0. So one or more following junk characters are printed until 0 is found. Commented Aug 3, 2019 at 11:18
  • 1
    @jszpilewski I figured out what was the problem and It was something related to what you said. cell_wrap_0 is a struct with a size field and I have to use it properly to print my variable. Commented Aug 3, 2019 at 22:10
  • @FFFF Great that you figured it out! Consider posting your fixed code as an answer so future readers can see what you did to resolve the issue. Commented Aug 5, 2019 at 13:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.