2012-06-17 62 views
-2

我已經創建了MATLAB代碼,但我想知道如果我能以簡單的形式將此MATLAB代碼轉換爲C++。MATLAB to C++編程幫助請

%# Plotting T coordinates which represent the temperature 
%# in the vertical 

clear all; 

T=[22 24 16.2 8.4 -0.3 -7.3 -20.3 -37.1 -56.7]; 
H=[0 914 1876 3141 4267 5830 7530 9590 12280]; 
%# Plotting H coordinates which represent the height 
%# in the vertical 

%# 3 point running mean 
Tmean = conv(T, ones(1,3)/3); 
Tmean_valid = Tmean(3:end-2); 

Hmean = conv(H,ones(1,3)/3); 
Hmean_valid = Hmean(3:end-2); 

figure(1); 
plot(Tmean_valid,H(2:end-1), ':*r'); 
hold on 
plot(T,H,':*g') 
legend('Running Mean','Temperature Profile') 
title('Temperature Running Mean as function of height') 
xlabel('Temperature(C)') 
ylabel('Height (m)')" 
+0

這一切都取決於你是多麼好的C++程序員。計算部分看起來很簡單,繪圖方面不那麼明顯。 – mathematician1975

+0

你需要一個圖形用戶界面(如果你仍然想保持繪圖),以及一個庫,可以爲你做卷積/ FFT – eqzx

+0

這就是我在想Mathmatician1975。我一直在想出一個用於卷積函數的C++代碼。這很難找到,因爲它們不是它的例子。 –

回答

0

如果你有MATLAB R13,你應該有MATLAB Compiler 3.0,這是能夠M代碼轉換爲C/C++代碼。只有當我瞭解文檔時纔是Windows。

如果使用編譯器,this documentation page should help you。對於圖形視圖,我認爲下面的命令應該可以工作(不是由我自己測試):mcc -B sgl mymainfile

我想你也可以直接從C++使用MCR(MATLAB Component Runtime),這個運行時是一個能夠運行M代碼的虛擬機。我不知道,因爲我從來沒有這樣做;)