c#数组转换成Matlab中的MWarray

本文关键字:中的 MWarray Matlab 数组 转换 | 更新日期: 2023-09-27 18:08:08

我有一个MxNx3矩阵,我想用MWArray将它转换到matlab中。
这是我的代码,但是没有CTOR。
有什么办法吗?

RGBImage image = _currentImage as RGBImage;
int height = image.Height;
int width = image.Width;
//transform the 1D array of byte into MxNx3 matrix 
byte[, ,] rgbByteImage = new byte[3, height, width];
if (image[0].Bpp > 16)
{
    for (int i = 0; i < height; i++)
    {
        for (int j = 0, k = 0; k < width; j = j + 3, k++)
        {
            rgbByteImage[0, i, k] = image[0].Data[i * width + j]; 
            rgbByteImage[1, i, k] = image[0].Data[i * width + j + 1]; 
            rgbByteImage[2, i, k] = image[0].Data[i * width + j + 2 ]; 
        }
    }
}
MWNumericArray tempArr = new MWNumericArray(rgbByteImage);

c#数组转换成Matlab中的MWarray

RGBImage image = _currentImage as RGBImage;
int height = image.Height;
int width = image.Width;
//transform the 1D array of byte into MxNx3 matrix 
byte[ , , ] RGBByteImage = new byte[3,height, width];
if (image[0].Bpp > 16)
{
    for (int i = 0; i < height; i++)
    {
        for (int j = 0, k = 0; k < width; j = j + 3, k++)
        {
            RGBByteImage[0, i, k] = image[0].Data[3 * i * width + j];
            RGBByteImage[1, i, k] = image[0].Data[3 * i * width + j + 1];
            RGBByteImage[2, i, k] = image[0].Data[3 * i * width + j + 2]; 
        }
    }
}
MWNumericArray matrix = null;
matrix = new MWNumericArray(MWArrayComplexity.Real, MWNumericType.Int8, 3,height, width);
matrix = RGBByteImage;

这就是我所发现的。

这里也有一个很好的教程http://domoreinlesstime.wordpress.com/2013/01/26/access-matlab-from-c/

请注意您对MWArray.dll文件(x64或x86)的正确引用。我已经浪费了一天左右的时间。