, , . , , MATLAB ( ) C++ ( ).
C++ , IDE C++ . , , C++. , Gnuplot, PPlot .., , :
Koolplot - , 2D-, . , C++ IDE .
#include "koolplot.h"
int main()
{
plotdata x(-6.0, 6.0);
plotdata y = sin(x) + x/5;
plot(x, y);
return 0;
}
GNUPlot, , , Gnuplot-iostream, gnuplot C++ - . - gnuplot C++ , . , , , . , gnuplot , include lib gnuplot IDE C++, . , Gnuplot C++ gnuplot-iostream, , .
#include <vector>
#include <cmath>
#include <boost/tuple/tuple.hpp>
#include "gnuplot-iostream.h"
int main() {
Gnuplot gp;
std::vector<boost::tuple<double, double, double, double> > pts_A;
std::vector<double> pts_B_x;
std::vector<double> pts_B_y;
std::vector<double> pts_B_dx;
std::vector<double> pts_B_dy;
for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
double theta = alpha*2.0*3.14159;
pts_A.push_back(boost::make_tuple(
cos(theta),
sin(theta),
-cos(theta)*0.1,
-sin(theta)*0.1
));
pts_B_x .push_back( cos(theta)*0.8);
pts_B_y .push_back( sin(theta)*0.8);
pts_B_dx.push_back( sin(theta)*0.1);
pts_B_dy.push_back(-cos(theta)*0.1);
}
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
gp << "plot '-' with vectors title 'pts_A', '-' with vectors title 'pts_B'\n";
gp.send1d(pts_A);
gp.send1d(boost::make_tuple(pts_B_x, pts_B_y, pts_B_dx, pts_B_dy));
}
MATLAB (, , MATLAB C++). MATLAB, C++, / MATLAB . MATLAB , ( ). MATLAB, engine.h MATLAB IDE C++, . Matlab Visual Studio C++ . ,
()
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "engine.h"
#define BUFSIZE 256
int main()
{
Engine *ep;
mxArray *T = NULL, *result = NULL;
char buffer[BUFSIZE+1];
double time[10] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
T = mxCreateDoubleMatrix(1, 10, mxREAL);
memcpy((void *)mxGetPr(T), (void *)time, sizeof(time));
engPutVariable(ep, "T", T);
engEvalString(ep, "D = .5.*(-9.8).*T.^2;");
engEvalString(ep, "plot(T,D);");
engEvalString(ep, "title('Position vs. Time for a falling object');");
engEvalString(ep, "xlabel('Time (seconds)');");
engEvalString(ep, "ylabel('Position (meters)');");
printf("Hit return to continue\n\n");
fgetc(stdin);
printf("Done for Part I.\n");
mxDestroyArray(T);
engEvalString(ep, "close;");
buffer[BUFSIZE] = '\0';
engOutputBuffer(ep, buffer, BUFSIZE);
while (result == NULL) {
char str[BUFSIZE+1];
printf("Enter a MATLAB command to evaluate. This command should\n");
printf("create a variable X. This program will then determine\n");
printf("what kind of variable you created.\n");
printf("For example: X = 1:5\n");
printf(">> ");
fgets(str, BUFSIZE, stdin);
engEvalString(ep, str);
printf("%s", buffer);
printf("\nRetrieving X...\n");
if ((result = engGetVariable(ep,"X")) == NULL)
printf("Oops! You didn't create a variable X.\n\n");
else {
printf("X is class %s\t\n", mxGetClassName(result));
}
}
printf("Done!\n");
mxDestroyArray(result);
engClose(ep);
return EXIT_SUCCESS;
}
Python , people like to ask (who is familiar with the matplotlib tool in Python). A very elegant interface is available for calling Python from C ++. a simple example might look like this ( source ), but matlabplotcpp.his available here .
#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main() {
plt::plot({1,3,2,4});
plt::show();
}
Hope this information can be helpful ...