Plot Over an Image, MATLAB Engine for C++ (Visual Studio 2017)
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vijay Kumar Polimeru
am 29 Apr. 2019
Kommentiert: omnia ahmed
am 1 Mär. 2022
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??
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!