H
hitbuyi
Guest
in MATLAB, plot a figure is so easy, like this way
figure(1);
plot(x1,y1);
figure(2);
plot(x1,y2);
Now I have call MATLAB function to plot figures in VS2015 sucessfully, BUT do not know how to add Figure Number(like figure(1), figur(2),.., in MATLAB ) my C code in VS2015 is as below
void mat_plot(Engine *eg, double *x, double *y, int N, char *LineStyle, double LineWidth, double MarkerSize)
{
int ret = 0;
mxArray *X = mxCreateDoubleMatrix(1, N, mxREAL);
mxArray *Y = mxCreateDoubleMatrix(1, N, mxREAL);
mxArray *MS = mxCreateDoubleScalar(MarkerSize);
memcpy(mxGetPr(X), x, N * sizeof(double));
memcpy(mxGetPr(Y), y, N * sizeof(double));
if ((ret = engPutVariable(eg, "X", X)) != 0)
printf("engPutVariable error:%d\n", ret);
if ((ret = engPutVariable(eg, "Y", Y)) != 0)
printf("engPutVariable error:%d\n", ret);
//gennerate the plot command
char plotCommand[256] = "fig=plot(X,Y,'";
//set line style and marker
if (strlen(LineStyle) > 0)
strncat(plotCommand, LineStyle, strlen(LineStyle));
else
{
strncat(plotCommand, "-", strlen("-"));
}
strncat(plotCommand, "',", strlen(LineStyle));
char temp[20] = "";
//set line width
if (LineWidth < 1.0)
LineWidth = 1.0;
strncat(plotCommand, "'LineWidth',", strlen("'LineWidth',"));
memset(temp, 0, sizeof(temp));
sprintf(temp, "%f,", LineWidth);
strncat(plotCommand, temp, strlen(temp));
//set marker size
strncat(plotCommand, "'MarkerSize',", strlen("'MarkerSize',"));
sprintf(temp, "%f", MarkerSize);
strncat(plotCommand, temp, strlen(temp));
strncat(plotCommand, ");", strlen(temp));
//plot
if ((ret = engEvalString(eg, plotCommand)) != 0)
{
printf("\nplot Command error:%s\n", plotCommand);
}
engEvalString(eg, "set(gcf,'color','w');");
printf("plot Command ok:%s\n", plotCommand);
//destroy mxArray,but they are still in matlab workspace
mxDestroyArray(X);
mxDestroyArray(Y);
}
1) how to add figure Number, furtherly
2) how to add ticks/lable in the plot
is there any examples ?
thanks a lot
Continue reading...
figure(1);
plot(x1,y1);
figure(2);
plot(x1,y2);
Now I have call MATLAB function to plot figures in VS2015 sucessfully, BUT do not know how to add Figure Number(like figure(1), figur(2),.., in MATLAB ) my C code in VS2015 is as below
void mat_plot(Engine *eg, double *x, double *y, int N, char *LineStyle, double LineWidth, double MarkerSize)
{
int ret = 0;
mxArray *X = mxCreateDoubleMatrix(1, N, mxREAL);
mxArray *Y = mxCreateDoubleMatrix(1, N, mxREAL);
mxArray *MS = mxCreateDoubleScalar(MarkerSize);
memcpy(mxGetPr(X), x, N * sizeof(double));
memcpy(mxGetPr(Y), y, N * sizeof(double));
if ((ret = engPutVariable(eg, "X", X)) != 0)
printf("engPutVariable error:%d\n", ret);
if ((ret = engPutVariable(eg, "Y", Y)) != 0)
printf("engPutVariable error:%d\n", ret);
//gennerate the plot command
char plotCommand[256] = "fig=plot(X,Y,'";
//set line style and marker
if (strlen(LineStyle) > 0)
strncat(plotCommand, LineStyle, strlen(LineStyle));
else
{
strncat(plotCommand, "-", strlen("-"));
}
strncat(plotCommand, "',", strlen(LineStyle));
char temp[20] = "";
//set line width
if (LineWidth < 1.0)
LineWidth = 1.0;
strncat(plotCommand, "'LineWidth',", strlen("'LineWidth',"));
memset(temp, 0, sizeof(temp));
sprintf(temp, "%f,", LineWidth);
strncat(plotCommand, temp, strlen(temp));
//set marker size
strncat(plotCommand, "'MarkerSize',", strlen("'MarkerSize',"));
sprintf(temp, "%f", MarkerSize);
strncat(plotCommand, temp, strlen(temp));
strncat(plotCommand, ");", strlen(temp));
//plot
if ((ret = engEvalString(eg, plotCommand)) != 0)
{
printf("\nplot Command error:%s\n", plotCommand);
}
engEvalString(eg, "set(gcf,'color','w');");
printf("plot Command ok:%s\n", plotCommand);
//destroy mxArray,but they are still in matlab workspace
mxDestroyArray(X);
mxDestroyArray(Y);
}
1) how to add figure Number, furtherly
2) how to add ticks/lable in the plot
is there any examples ?
thanks a lot
Continue reading...