读取 MEX 文件中的 4D 数组

2024-04-27

我在 MATLAB 中有一个 4 维数组;我正在尝试访问 MEX 函数中的数组。下面创建“testmatrix”,一个 4 维矩阵,已知数据为uint8 type.

%Create a 4D array 2x,2y, rgb(3), framenumber(from 1 to 5)
%Framenumber from 1 to 5

testmatrix(1,1,1,1) = 0;
testmatrix(1,1,1,2) = 1;
testmatrix(1,1,1,3) = 2;
testmatrix(1,1,1,4) = 3;
testmatrix(1,1,1,5) = 4;

testmatrix(1,1,2,1) = 5;
testmatrix(1,1,2,2) = 6;
testmatrix(1,1,2,3) = 7;
testmatrix(1,1,2,4) = 8;
testmatrix(1,1,2,5) = 9;

testmatrix(1,1,3,1) = 10;
testmatrix(1,1,3,2) = 11;
testmatrix(1,1,3,3) = 12;
testmatrix(1,1,3,4) = 13;
testmatrix(1,1,3,5) = 14;

testmatrix(1,2,1,1) = 15;
testmatrix(1,2,1,2) = 16;
testmatrix(1,2,1,3) = 17;
testmatrix(1,2,1,4) = 18;
testmatrix(1,2,1,5) = 19;

testmatrix(1,2,2,1) = 20;
testmatrix(1,2,2,2) = 21;
testmatrix(1,2,2,3) = 22;
testmatrix(1,2,2,4) = 23;
testmatrix(1,2,2,5) = 24;

testmatrix(1,2,3,1) = 25;
testmatrix(1,2,3,2) = 26;
testmatrix(1,2,3,3) = 27;
testmatrix(1,2,3,4) = 28;
testmatrix(1,2,3,5) = 29;

testmatrix(2,1,1,1) = 30;
testmatrix(2,1,1,2) = 31;
testmatrix(2,1,1,3) = 32;
testmatrix(2,1,1,4) = 33;
testmatrix(2,1,1,5) = 34;

testmatrix(2,1,2,1) = 35;
testmatrix(2,1,2,2) = 36;
testmatrix(2,1,2,3) = 37;
testmatrix(2,1,2,4) = 38;
testmatrix(2,1,2,5) = 39;

testmatrix(2,1,3,1) = 40;
testmatrix(2,1,3,2) = 41;
testmatrix(2,1,3,3) = 42;
testmatrix(2,1,3,4) = 43;
testmatrix(2,1,3,5) = 44;

testmatrix(2,2,1,1) = 45;
testmatrix(2,2,1,2) = 46;
testmatrix(2,2,1,3) = 47;
testmatrix(2,2,1,4) = 48;
testmatrix(2,2,1,5) = 49;

testmatrix(2,2,2,1) = 50;
testmatrix(2,2,2,2) = 51;
testmatrix(2,2,2,3) = 52;
testmatrix(2,2,2,4) = 53;
testmatrix(2,2,2,5) = 54;

testmatrix(2,2,3,1) = 55;
testmatrix(2,2,3,2) = 56;
testmatrix(2,2,3,3) = 57;
testmatrix(2,2,3,4) = 58;
testmatrix(2,2,3,5) = 59;

testmatrix = uint8(testmatrix);

但是,当我尝试使用时,我得到的尺寸不正确mxGetNumberOfDimensions我的代码如下:

#include "mex.h"

void
mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
//Check - expect 1 input, expect 1 outputs
    if (nrhs != 1) {
        mexErrMsgIdAndTxt( "MATLAB:24bit_pixel_from_uint8_rgb:invalidNumInputs",
                "One input argument required.");
    }
    if (nlhs > 1) {
        mexErrMsgIdAndTxt( "MATLAB:24bit_pixel_from_uint8_rgb:maxlhs",
                "Too many output arguments.");
    }    

//declare variables
    mxArray *a_in_m, *b_out_m;
    double *a, *b, *c, *d;
    int dimx, dimy, numdims;
    int dima, dimb, dimc, dimd;
    int i,j,M,N,L,W;
    //Comment
    mwSize *dim_array, dims;
    dims      = mxGetNumberOfDimensions(prhs[0]);
    dim_array = mxGetDimensions(prhs[0]);
    M            = dim_array[0];
    N            = dim_array[1];
    L            = dim_array[2];
    W            = dim_array[3];
    mexPrintf("dims: %d\n",dims);
    mexPrintf("M: %d\n",M);
    mexPrintf("N: %d\n",N);
    mexPrintf("L: %d\n",L);
    mexPrintf("W: %d\n",W);

}

此 mex 文件的结果testarray如下:

>> rgb_to_uint8 testmatrix
dims: 2
M: 1
N: 10
L: 1634887535
W: 1766203501

dims第一个元素是正确的,但其他一切都是错误的 - 我一定是在做一些根本不正确的事情。任何正确方向的想法或指示将不胜感激;谢谢大家!


当你调用像这样的函数时

rgb_to_uint8 testmatrix

这相当于这样称呼它

rgb_to_uint8('testmatrix')

与此相同:

c = 'testmatrix'
rgb_to_uint8(c)

这当然是一个大小为 1x10 (2D) 的字符数组。您需要像函数一样调用:

rgb_to_uint8(testmatrix)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

读取 MEX 文件中的 4D 数组 的相关文章

  • 如何用php将文件内容转换为字节数组

    我想用PHP将上传的文件保存 插入 到数据库中 数据库字段的类型是varbinary 最后 我想要获得 VarBinary 输出 的内容 就像在 C 中读取文件然后将其存储在字节数组中并将数组插入到 VarBinary 中一样 我与数据库的
  • 我如何在 C++ 中将数组存储到队列

    queue lt int gt qq for int i 0 i lt N i int cc 2 i i 1 qq push cc N很大但不精确 所以我想使用队列 我想存储很多数组来排队 但是 qq 存储的数组是同一个 我该怎么做 你的代
  • Fortran 中的数组第一个索引

    我认为 Fortran 中数组的第一个索引是 1 但是为什么这段代码可以工作呢 代码是 Wavewatch 的修改部分 http polar ncep noaa gov waves wavewatch http polar ncep noa
  • 比较通用列表和数组

    为什么 generic list 比 array 慢 通用列表比数组稍慢 但在大多数情况下您不会注意到 主要与稍微复杂的查找有关 据说 List 在幕后 使用数组 但不能保证以与数组相同的方式将节点保留在相邻内存中 然而 我早在 2005
  • 最后一项具有不同类型的元组(首先从剩余元素开始)

    我有一个类型Foo那是一个Array可以包含任意数量的Bar元素 带有可选的最后一个Qux元素 以下是一些有效数据的示例 bar qux bar qux bar bar bar bar bar bar bar bar qux 无效数据示例
  • C 在函数中返回数组

    我对 C 比较陌生 我习惯用 Java 编程 所以我发现 C 在涉及数组的方面有点困难 我仍然对这些案例感到困惑 int a int a int a 在java中 我会做这样的事情来在函数中返回一个数组 int returnArr int
  • 如何将向量转换为数组

    我如何转换std vector
  • 估算缺失数据,同时强制相关系数保持不变

    考虑以下 excel 数据集 m r 2 0 3 3 0 8 4 0 1 3 2 1 5 2 2 3 1 9 2 5 1 2 3 0 2 0 2 6 我的目标是使用以下条件填充缺失值 将上述两列之间的成对相关性表示为 R 大约 0 68 将
  • 删除队列对象数组

    我正在研究一个包含数组的对象queues数组长度在调用构造函数之前才确定 基本上看起来像下面这样 include
  • 如何过滤javascript对象数组

    我有两个数组 我正在使用 PubSidebar 过滤基于 groupKey 的内容 let groupKey oaDeal Journals Deposit This array of object will be filtering wi
  • 如何从绘图处理程序中绘图?

    我有绘图的处理程序或图形的处理程序 例子 h plot 1 0 2 10 xx get h xx DisplayName Annotation 1x1 handle Color 0 0 1 LineStyle LineWidth 0 500
  • 傅里叶变换定理 matlab

    我目前正在尝试理解二维傅里叶位移定理 根据我到目前为止所了解到的情况 图像空间中的平移会导致相位差异 但不会导致频率空间中的幅度差异 我试图用一个小例子来演示这一点 但它只适用于行的移位 而不适用于列的移位 这是一个小演示 我只在这里显示幅
  • 将键值对添加到数组中的所有对象

    我想向数组中的所有对象添加一个键 值参数 eg var arrOfObj name eve name john name jane 现在我想向所有对象添加一个新参数 isActive 以便生成的数组如下所示 eg name eve isAc
  • C++:创建一个由用户输入大小的数组

    我想知道我们是否可以创建一个具有用户指定大小的数组 Ex int a cout lt lt Enter desired size of the array cin gt gt a int array a 上面的程序将不起作用 因为数组大小必
  • Angular 2循环遍历列表有一些延迟

    如何使用 Angular 2 和 TypeScript 以一定延迟循环遍历数组 我有一个数组 students Array
  • 为什么超过44个字符时打印随机符号

    我正在从 C 编程 现代方法 一书中学习 C 现在我正在进行有关数组的练习 练习之一是编写一个过滤器 以不同的方式打印输入消息 到目前为止 参见下面的代码 一切正常 直到字符数超过 44 然后它打印随机符号 如果字符数低于 44 则一切正常
  • 使用另一个数组中的值转换所有数组键

    我有很多数组 是从 csv 文件生成的 在所有数组中 第一个数组对象是 csv 标题 请参阅下面的示例 总之 第一个数组的值 即 key 0 和 value report date 应替换所有后续数组的所有键 因此 对除第一个数组之外的所有
  • 在Java中将浮点数组写入文件

    我正在读取 NetCDF 文件 我想将每个数组作为浮点数组读取 然后将浮点数组写入新文件 如果我读取浮点数组 然后迭代数组中的每个元素 使用 DataOutputStream 我可以使其工作 但这非常非常慢 我的 NetCDF 文件超过 1
  • 声纳违规:安全性 - 使用 byte[] 时直接存储数组

    我确实遇到过以下两篇关于类似问题的帖子声纳违规 https stackoverflow com questions 11580948 sonar violation security array is stored directly and
  • 如何从对应的数组值中获取数组键?

    您可以轻松地通过其键获取数组值 如下所示 value array key 但如果我有该值并且想要它的密钥怎么办 获得它的最佳方式是什么 你可以使用array search https www php net manual en functi

随机推荐