2015-05-19 30 views
-6

我有這個C#代碼,我試圖將其轉換爲MATLAB代碼,想知道是否有人會解釋如何在MATLAB中完成。如何將C sharp代碼轉換爲MATLAB?

private static byte[] CalcLRC(byte[] cmnd) 
{ 
int i, j, bSize = cmnd.Length; 
uint lrc,high,low,CR,LF; 
string temp; 
byte[] bytes = new byte[((bSize)+4)]; 
lrc=0x00; 
CR = 0x0d; 
LF = 0x0a; 
//loop through input byte array 
for (i=0; i<cmnd.Length; i++) 
{ 
//sum message bytes 
lrc = lrc + (uint) cmnd[i]; 
//insert each message byte into result 
bytes[i] = cmnd[i]; 
} 
//remove remainder 
if (lrc > 256) 
{ lrc = lrc - (uint) (256 * Math.Floor((double) lrc/256)); 
} 
//perform 2's complement on sum 
lrc = (ushort)(~lrc); 
lrc = lrc + 1; 
//remove remainder 
if (lrc > 256) 
{ lrc = lrc - (uint)(256 * Math.Floor((double)lrc/256)); 
} 
//split into high and low bits 
temp = lrc.ToString("X"); 
high = (uint)temp[0]; 
low = (uint)temp[1]; 
//insert high, low, carriage return, and line feed into result 
bytes[(bSize)]=(byte) high; 
bytes[(bSize+1)]=(byte) low; 
bytes[(bSize+2)]=(byte) CR; 
bytes[(bSize + 3)] = (byte) LF; 
//return result byte array with input, LRC, CR, LF 
return bytes; 

它怎麼轉換成MATLAB?

+1

哪裏有遺囑,有辦法:) – rcs

+0

方法是打電話:上班 – Laykker

回答

1

也可以打電話從MATLAB C#代碼,這樣就可以在MATLAB檢查使用相同的方法,這個環節出了更多的細節:

Call .NET libraries from Matlab

周圍的另一種方式是讓你瞭解MATLAB,它可能是值得的