Matlab engine eval: should I use the exception message or the error stream content ?

17 ビュー (過去 30 日間)
Felix Arnoux
Felix Arnoux 2021 年 1 月 7 日
コメント済み: Felix Arnoux 2021 年 1 月 13 日
Hello,
When I use the Matlab engine eval, I can provide output and error streams. But the eval() can also throw exceptions, which contains error messages:
Then which one should I use: the exception message or the error stream ?
Moreover, if something is returned in the error stream, is it always an error ? or warnings can also appear in this stream ?
Many thanks !

採用された回答

Pranav Verma
Pranav Verma 2021 年 1 月 13 日
Hi Felix,
The eval function in matlab::engine::MATLABEngine takes three parameters as input,
void eval(const matlab::engine::String &statement,
const std::shared_ptr<matlab::engine::StreamBuffer> &output = std::shared_ptr<matlab::engine::StreamBuffer> (),
const std::shared_ptr<matlab::engine::StreamBuffer> &error = std::shared_ptr<matlab::engine::StreamBuffer> ())
  • 1st parameter is the MATLAB statement to evaluate
  • 2nd parameter is the stream buffer for storing the output of the MATLAB statement
  • 3rd parameter is the stream buffer for storing the error message from the MATLAB statement
You can use the error stream as it contains the error thrown by the MATLAB statement in case it fails. The error stream contains the error thrown by the MATLAB statement and not the warnings.
The matlab::engine::MATLABEngine documentation explains well about the exceptions and output/error streams in eval function along with several other functions used to evaluate MATLAB code.
Thanks

その他の回答 (0 件)

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by