matlab如何把cell转int_求助:Matlab中cell转化为double

回复3#

f函数就是读入图像,f=imread('car_2.bmp');

现在的问题就是:不用元胞数组则矩阵维数不匹配;用了元胞数组则下一步函数的输入不能为cell。都快晕了。

以前发过一个帖子,在第二页中间,“求助:matlab提取子矩阵”。链接发不上来。

这是以前的程序。提示矩阵维数不匹配。

错误信息:

??? Subscripted assignment dimension mismatch.

Error in ==> main at 18

s(xcount,ycount)=f(r,c);

f=imread('car_2.bmp');                           % 读取图像;

[x,y]=size(f);                                   % x,y为图像的行数和列数;

m=20;n=30;                                        % 手动定义子图像的行数和列数;

rx=1;cy=1;

s=zeros(10);                                     % s表示子矩阵;

t=zeros(10);                                   % t为阈值矩阵;

rowhigh=rx+m-1;                                   % rowhigh和colhigh是子图像历遍的终点,即为右下角的坐标;

colhigh=cy+n-1;

xc

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用MATLAB引擎库来读取MAT文件的数据,然后将其换为QT的数据类型。以下是一个示例代码: ```c++ #include <QCoreApplication> #include <QDebug> #include <engine.h> #include <matrix.h> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // Start MATLAB engine Engine *ep; if (!(ep = engOpen(""))) { qDebug() << "Can't start MATLAB engine"; return EXIT_FAILURE; } // Read the mat file mxArray *matData; matData = engGetVariable(ep, "cellData"); // Get the number of cells in the cell array int numCells = mxGetNumberOfElements(matData); // Loop through each cell and extract the data for (int i = 0; i < numCells; i++) { mxArray *cell = mxGetCell(matData, i); // Extract the data type and size of the cell contents mxClassID dataType = mxGetClassID(cell); const mwSize *dims = mxGetDimensions(cell); int numRows = dims[0]; int numCols = dims[1]; // Extract the actual data void *data = mxGetData(cell); // Convert the data to a QT data type if (dataType == mxDOUBLE_CLASS) { double *doubleData = static_cast<double*>(data); // Do something with the double data qDebug() << "Double data for cell" << i << ":"; for (int row = 0; row < numRows; row++) { for (int col = 0; col < numCols; col++) { qDebug() << doubleData[row * numCols + col]; } } } else if (dataType == mxINT32_CLASS) { int *intData = static_cast<int*>(data); // Do something with the integer data qDebug() << "Integer data for cell" << i << ":"; for (int row = 0; row < numRows; row++) { for (int col = 0; col < numCols; col++) { qDebug() << intData[row * numCols + col]; } } } // Clean up the mxArray mxDestroyArray(cell); } // Clean up the engine engClose(ep); return a.exec(); } ``` 在上面的示例代码,我们首先启动了MATLAB引擎,并使用`engGetVariable`函数从MAT文件读取名为`cellData`的变量。然后,我们遍历每个单元格,提取其数据类型、大小和实际数据。最后,我们将数据换为QT数据类型,并进行处理。 请注意,这只是一个示例代码,并且仅支持`mxDOUBLE_CLASS`和`mxINT32_CLASS`数据类型。如果您需要处理其他数据类型,请相应地修改代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值