Azzera filtri
Azzera filtri

Plot Over an Image, MATLAB Engine for C++ (Visual Studio 2017)

5 visualizzazioni (ultimi 30 giorni)
Dear Community Members,
I am trying to plot a graph over an image, I successfully did in MATLAB, using the following code
clc
clear all
close all
set(0,'defaultaxesfontsize', 14)
set(0,'defaultaxesfontname', 'Palatino Linotype')
ForceDisp = load('Outputs/Panel_Disp_Node_4.out');
Disp = ForceDisp(:,2);
Force = ForceDisp(:,1);
Gamma_lt = Disp/1398;
Tau_lt = Force*1000/(1398*178);
figure(1)
plot (Gamma_lt(1:end,:),Tau_lt(1:end,:))
xlabel('Shear Strain');
ylabel('Shear Stress (Mpa)');
% replace with an image of your choice
img = imread('CA2 Final.png');
% set the range of the axes
% The image will be stretched to this.
min_x = -0.040;
max_x = 0.040;
min_y = -4.0;
max_y = 4.0;
% Flip the image upside down before showing it
imagesc([min_x max_x], [min_y max_y], flipud(img));
% NOTE: if your image is RGB, you should use flipdim(img, 1) instead of flipud.
hold on
plot(Gamma_lt, Tau_lt, 'LineWidth',2,'Color',[0.850980401039124 0.325490206480026 0.0980392172932625]);
xlabel('Shear Strain')
ylabel('Shear Stress (Mpa)')
hold off
% set the y-axis back to normal.
set(gca,'ydir','normal');
Later, I am trying to plot the same using Matlab Enginer API in Visual Studio C++ (2017), But it is not working, I was unable to see the errors also. The code used in Visual C++ is as follows
#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);
}
engEvalString(m_pEngine, "clc;");
engEvalString(m_pEngine, "close all;");
engEvalString(m_pEngine, "clear all;");
engEvalString(m_pEngine, "figure");
engEvalString(m_pEngine, "img = imread('CA2 Final.png')");
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;
}
Could anybody help me understand where I am doing the error??

Risposta accettata

Vijay Kumar Polimeru
Vijay Kumar Polimeru il 30 Apr 2019
Problem Solved. I forgot to change the directory in MATLAB to the c++ solution directory.

Più risposte (0)

Categorie

Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange

Prodotti


Release

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by