필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Amittai Aviram
Amittai Aviram 2017년 1월 17일
답변: Amittai Aviram 2017년 1월 17일
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!

답변 (1개)

Amittai Aviram
Amittai Aviram 2017년 1월 17일
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.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by