![]() |
#2
荆楚之恋2016-10-02 20:32
|
操作系统: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;
}
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);
% 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);