필터 지우기
필터 지우기

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 CenterFile Exchange에서 Write 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