matlab c++ 画图【转载】
来源:互联网 发布:vscode eslint 编辑:程序博客网 时间:2024/06/04 19:04
原文:http://blog.csdn.net/owldestiny/article/details/4210177
最近有朋友问我他照着我之前的一篇文章(http://blog.csdn.net/owldestiny/archive/2009/03/07/3966340.aspx )
做画图的时候画不出来图像,不知道如何解决,自己试了一下,搞定了在这里贴出来
首先matlab文件他是这样写的:
- function mfun()
- x=-10:0.1:10;
- y=sin(x);
- plot(x,y)
C++代码是:
- int main()
- {
- cout<<"test";
- drawInitialize();
- mfun();
- drawTerminate();//terminate
- return 0;
- }
C++代码最后一句建议加上system("pause");
这样如果程序运行过快最后还是能停下等待按键,就可以看到程序运行的结果;
加上之后控制台中报错为:
testWarning: 1 visible figure(s) exist at MCR termination.
If your application has terminated unexpectedly, please note that
applications generated by the MATLAB Compiler terminate when there are no
visible figure windows. See the documentation for WaitForFiguresToDie and
WAITFORCALLBACKS for more information.
Warning: Class
'graph2d.lineseries'
in use at MCR termination.
If your application has terminated unexpectedly, please note that
applications generated by the MATLAB Compiler terminate when there are no
visible figure windows. See the documentation for WaitForFiguresToDie and
WAITFORCALLBACKS for more information.
Warning: Objects of graph2d.lineseries class exist - not clearing this class
or any of its super-classes
大致的意思就是图片在退出MCR时仍然存在,这个是不允许的,terminate时MCR就不存在了,图片也不可能继续显示,
解决的方法是将MCR存在的时间延长,可以在Matlab代码中加入延时程序或等待按键代码,我采用的是等待按键,
- function [t]=draw()
- x=-10:0.1:10;
- y=sin(x);
- figure(1)
- plot(x,y)
- hold on
- t=1;
- w=1;
- while w,
- w=waitforbuttonpress
- end
最后一行就是等待鼠标按键,w变为0,循环终止,draw函数终止,MCR退出;
C++的代码也进行了一点修改,
- #pragma comment(lib,"draw.lib")
- #include "draw.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- cout<<"test";
- drawInitialize();
- short int nargout = 1;
- mwArray t(1,1,mxINT8_CLASS);
- draw(nargout, t);
- drawTerminate();//terminate
- system("pause");
- return 0;
- }
这样就可以实现了,具体代码在这里(http://download.csdn.net/source/1341025 )可以下载到,,欢迎大家与我讨论,mailto:chen0510566@163.com
0 0
- matlab c++ 画图【转载】
- 【转载】Matlab画图命令介绍
- MATLAB各种概率分布画图(转载)
- matlab画图
- matlab 画图
- matlab 画图
- matlab 画图
- MatLab 画图
- matlab画图
- matlab 画图
- matlab画图
- matlab 画图
- matlab画图
- matlab画图
- matlab画图
- Matlab画图
- matlab画图
- matlab 画图
- 删除内容中的空格
- 中英文字符串求长度、截取问题
- 游戏开发中的数学和物理算法(6):圆和球的碰撞检测
- unity android环境
- 一种高效简单的缓存机制
- matlab c++ 画图【转载】
- 域名年龄-SEO搜索引擎优化
- 【Cocos2d-x】 关于IOS设置竖屏后,运行会报错的解决方法
- android碎片Fragment简介详解
- 图片处理类,用来生成缩略图
- 黑马程序员---学生管理系统 (转载)
- iOS-UITextField类
- Lua中的IO库
- (转)linux口令相关文件(/etc/passwd和/etc/shadow)