フィルターのクリア

No errors printing in MATLAB Command window, when I call it from c++

3 ビュー (過去 30 日間)
Vijay Kumar Polimeru
Vijay Kumar Polimeru 2019 年 5 月 2 日
編集済み: Vijay Kumar Polimeru 2019 年 5 月 2 日
I am working on a Opensource code called OpenSEES, which is written in Visual Studio C++. I have linked MATLAB to C++ using MATLAB Engine API for C++. I have called a user defined matlab function from c++ to plot two variables. My code is working fine, all plots are coming as I expected. But one problem I am facing is, in case of any errors in the matlab function, I am not getting any erros displayed in the command window. If I run the same code using dummy input variables in the usual matlab software, code is showing bugs in command window in RED Color with a beep sound.
When I call the same code from C++, I am able to hear only beep sound but no display of errors. Below mentioned is the code I am using, could anybody please tell me, How can I get the errors printed in command window, when I called it from C++.
(I am using MATLAB 2015a in windows 7 system).
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <string.h>
#include "engine.h"
int main()
{
/* open matlab engine */
Engine *m_pEngine;
m_pEngine = engOpen(NULL);
if (m_pEngine == NULL)
{
std::cout << "Error" << std::endl;
exit(1);
}
engSetVisible(m_pEngine, 1);
% Trying to change thw matlab working directory from C++ program, but no success
engEvalString(m_pEngine, "cd 'E:\PhD Working Folder\0_OPS_GitHub\SRC\IITB_VijayKumar\MATLAB Plots'");
engEvalString(m_pEngine, "clc;");
engEvalString(m_pEngine, "close all;");
engEvalString(m_pEngine, "clear all;");
engEvalString(m_pEngine, "disp('First Program');"); %/*I am expecting this to get printed in the command window*/
engEvalString(m_pEngine, "figure");
engEvalString(m_pEngine, "img = imread('CA2 Final.png')"); % There is no file called CA2 Final.png, It is an error, expecting to get displayed
engEvalString(m_pEngine, "min_x = -0.040; max_x = 0.040; min_y = -4.0; max_y = 4.0");
engEvalString(m_pEngine, "imagesc([min_x max_x], [min_y max_y], flipud(img));");
system("pause");
engEvalString(m_pEngine, "close;"); // Closes the matlab engine
return 0;
}

回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C++ Functions Callable from MATLAB (MEX Files) についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by