| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3010 人关注过本帖
标题:Matalb与C混编时矩阵无法传到编译好的mex文件
只看楼主 加入收藏
荆楚之恋
Rank: 1
等 级:新手上路
帖 子:16
专家分:2
注 册:2013-5-6
结帖率:100%
收藏
 问题点数:0 回复次数:1 
Matalb与C混编时矩阵无法传到编译好的mex文件
大家帮我看下,编译通过了,也能调用,就是矩阵无法传入。

操作系统:Win7 64位  MATLAB版本:R2014a 64位

程序代码:
#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    int *inData;
    int *outData;
    int number;
    int M,N;
    int i,j,k,l;
    int count = 0;
    
    if(nrhs!=1) 
    {
        mexErrMsgTxt("One inputs required./n"); 
    }
    if(!mxIsDouble(prhs[0])) 
    {
        mexErrMsgTxt("the Input Matrix must be double!/n"); 
    }
    
    inData = mxGetPr(prhs[0]);
    M = mxGetM(prhs[0]);
    N = mxGetN(prhs[0]);
    plhs[0] = mxCreateDoubleMatrix(9,4,mxREAL);
    plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL);
    outData = mxGetPr(plhs[0]);
    number = mxGetScalar(plhs[1]);

    for (i = 0; i < M; ++i)    
    {
        for (j = i+1; j < M; ++j)    
        {
            if (inData[i*M+j])    
            {
                for (k = j + 1; k < M; ++k)    
                {
                    if (inData[i*M+k] && inData[j*M+k])        
                    {
                        for (l = j+1; l < M; ++l)
                        {
                            if (!inData[k*M+l])                
                            {
                                if ((inData[i*M+l] && inData[j*M+l]) && (l>k))                      
                                {
                                    outData[count] = i+1;
                                    outData[9+count] = j+1;
                                    outData[18+count] = k+1;
                                    outData[27+count] = l+1;
                                    count += 1;
                                }
                            }            
                            else if (inData[k*M+l])
                            {
                                if ((inData[i*M+l] && !inData[j*M+l]) ||
                                (!inData[i*M+l] && inData[j*M+l]))                
                                {
                                    outData[count] = i+1;
                                    outData[9+count] = j+1;
                                    outData[18+count] = k+1;
                                    outData[27+count] = l+1;
                                    count += 1;
                                }
                            }                                            
                        }
                    }
                }
            }
        }
    }
    number = count;
}



程序代码:
% function [c4,n4] = findDTriangles( graph )
% c4: set of two triangles with two common nodes, k*4, each column is the nodes in two triangles
% n4: number of two triangles with two common nodes

graph = [ 0 1 1 1 1 0;
          1 0 1 1 1 0;
          1 1 0 0 1 0;
          1 1 0 0 1 1;
          1 1 1 1 0 1;
          0 0 0 1 1 0 ];
graph = sparse(graph);

[c4,n4] = GetDTriangles2(graph);
搜索更多相关主题的帖子: required include Matrix double number 
2016-10-02 13:51
荆楚之恋
Rank: 1
等 级:新手上路
帖 子:16
专家分:2
注 册:2013-5-6
收藏
得分:0 
找到原因了,定义的指针应该为double类型的,太大意了
2016-10-02 20:32
快速回复:Matalb与C混编时矩阵无法传到编译好的mex文件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018110 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved