用Matlab與c++程式產生的資料檔案繪製sin函數

來源:互聯網
上載者:User

標籤:matlab   sin函數   

軟體: MatlabR2014a  CodeBlock

 

1.建立個工程


2.輸入程式,求得座標並儲存到txt檔案中


3.用MATLAB建個M檔案


4.輸入繪圖代碼,


5.點擊運行,M檔案儲存在建立工程所在的檔案夾下


6.繪圖完成


7.如果想把映像以其他格式儲存,則點擊檔案->另存新檔,選擇檔案類型,這裡選擇pdf格式,,這就是儲存下來的映像。


總結: 本來很簡單的東西,上課聽了之後沒動手實踐,同學一問發現自己根本沒記住,-_-#

自己好好反思一下吧。

cpp原始碼:

//  實際應用---函數圖象#include <iostream>#include <fstream>//輸入/輸出流#include <cmath>using namespace std;int main(){ofstream out_y("y.txt");  //ofstream---輸出資料流,out--對象ofstream out_x("x.txt");int i,M=100;float dx=0.2;for(i=0;i<=M;i++){out_x<<i*dx<<'\t';out_y<<sin(i*dx)<<'\t';}out_x.close();out_y.close();return 0;}

Matlab代碼:

load x.txtload y.txtplot(x,y)


用Matlab與c++程式產生的資料檔案繪製sin函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.