2015-05-19 32 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,它可能是值得的