VS2015 call MATLAB to plot a figure, how to add Figure N in plotted figure similary in MATLAB RRS feed

  • Question

  • in MATLAB, plot a figure is so easy, like this way





    Now I have called 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  

    static 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));
    		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));
    	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


    1) how to add figure Number, furtherly

    2) how to add ticks/lable in the plot

    Is there any examples ?

    thanks a lot 

    Monday, August 10, 2020 10:33 AM

All replies

  • Hi,

    Thank you for posting here.

    >>VS2015 call MATLAB to plot a figure, how to add Figure N in plotted figure similary in MATLAB

    According to the issue, it is more related to the MATLAB. I suggest you should ask it in a MATLAB — Answers forum. And this thread will be moved to Off-Topic Posts.

    Best Regards,

    Jeanine Zhang

    "Visual c++" forum will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
    For more information, please refer to the sticky post.

    Tuesday, August 11, 2020 1:59 AM