日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

matlab c++ 画图【转载】

發布時間:2025/3/21 c/c++ 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab c++ 画图【转载】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文:http://blog.csdn.net/owldestiny/article/details/4210177



最近有朋友問我他照著我之前的一篇文章(http://blog.csdn.net/owldestiny/archive/2009/03/07/3966340.aspx?)

做畫圖的時候畫不出來圖像,不知道如何解決,自己試了一下,搞定了在這里貼出來

首先matlab文件他是這樣寫的:

[cpp]?view plaincopy
  • function?mfun()??
  • x=-10:0.1:10;??
  • y=sin(x);??
  • plot(x,y)??
  • C++代碼是:

    [cpp]?view plaincopy
  • 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代碼中加入延時程序或等待按鍵代碼,我采用的是等待按鍵,

    [cpp]?view plaincopy
  • 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++的代碼也進行了一點修改,

    [c-sharp]?view plaincopy
  • #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


    總結

    以上是生活随笔為你收集整理的matlab c++ 画图【转载】的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。