Borrar filtros
Borrar filtros

Do C++ STL functions work in S-function code?

3 visualizaciones (últimos 30 días)
Amittai Aviram
Amittai Aviram el 17 de En. de 2017
Respondida: Amittai Aviram el 17 de En. de 2017
I tried to print to stdout using std::cout << myMessage << std::endl, but the message does not appear, either in the console or the terminal from which I launched MATLAB, whereas printf works as expected. Why does std::cout not work?
Background:
  • I created a minimal model, threeModel.slx, containing an S-Function block, in local directory working.
  • I copied matlab/2016b/toolbox/simulink/simdemos/simfeatures/src/timestwo.c as working/three.cpp.
  • I #include d iostream and cstdio into three.cpp .
  • I inserted the following code into three.cpp at the end of function mdlOutputs: std::cout << "Testing cout." << std::endl; printf("Testing printf."):
  • I compiled with MEX: >> mex three.cpp (Built normally.)
  • I set the S-Function block's S-Function name parameter to three and left the other parameters with default settings (empty).
When I ran simulation (^T), I saw "Testing printf" (repeatedly) in the console window from which I had launched MATLAB, but no "Testing cout." Why not? Thanks!

Respuestas (1)

Amittai Aviram
Amittai Aviram el 17 de En. de 2017
I have discovered that output to std::cout gets routed to the Diagnostic Viewer: if I click on "View diagnostics" at the bottom of the model window, I can see it. Now my question is how to route the output elsewhere, e.g., to the MATLAB console.

Categorías

Más información sobre Configure and View Diagnostics en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by