When I run this portion of my code I get a fatal crash error, I am trying to update the code the best that I know how but keep getting the crash. First chunk of code calls up the second chunk... Can someone help me update this code?
% Attempt to update Q using the mex file update
try
Q = updateQ(Q, counts(indicesList));
catch exception
% Failed to call updateQ so compile all functions if a compiler
% is installed on the system
% Compiliing is different on Linux and Windows
if(isunix)
mex -largeArrayDims updateQ.c
mex -largeArrayDims calculateE.c
mex -largeArrayDims symmeig.c -lmwlapack
elseif(ispc)
ext = mexext;
arch = ext(end-1:end);
compiler = mex.getCompilerConfigurations().Manufacturer;
if(strcmp(compiler, 'LCC'))
folder = 'lcc';
elseif(strcmp(compiler, 'GNU'))
folder = 'GNU';
else
error('No compiler selected?');
end
%% lapacklib = fullfile(matlabroot, 'extern', 'lib', , 'mingw64', 'libmwlapack.lib');
lapacklib = fullfile(matlabroot,'extern','lib','win64','microsoft','libmwlapack.lib');
mex('-largeArrayDims', 'symmeig.c', lapacklib)
mex('-largeArrayDims', 'updateQ.c')
mex('-largeArrayDims', 'calculateE.c')
end
% Update Q now the compilation has succeeded
Q = updateQ(Q, counts(indicesList));
end
#include "mex.h"
/* Update summarisation matrix Q stored in upper packed format with the
* next spectrum
*
* Arguments:
* Q - current iteration of Q in upper packed format
* x - spectrum update Q with
*/
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray*prhs[] )
{
double *Q, *x;
int i, j, index;
int xSize = mxGetNumberOfElements(prhs[1]);
/* Output the updated Q */
plhs[0] = mxDuplicateArray(prhs[0]);
Q = mxGetDoubles(prhs[0]);
x = mxGetDoubles(prhs[1]);
for(j = 0; j < xSize; j++) {
for(i = 0; i <= j; i++) {
index = (i+j*(j+1)/2);
Q[index] += x[i] * x[j];
}
}
}

 채택된 답변

James Tursa
James Tursa 2020년 4월 11일
편집: James Tursa 2020년 4월 11일

1 개 추천

The use of mxGetDoubles( ) requires that the code is compiled with R2018a or later, and that you use the '-R2018a' option instead of the '-largeArrayDims' option when you compile. E.g.,
mex('-R2018a', 'symmeig.c', lapacklib)
mex('-R2018a', 'updateQ.c')
mex('-R2018a', 'calculateE.c')
What version of MATLAB are you using?
Also, that mex routine can easily bomb if you don't pass in the correct arguments (easy to run off the end of valid memory) since there are no checks in the code for valid size and type of inputs. How are you calling it? (variable types and sizes)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

질문:

2020년 4월 3일

편집:

2020년 4월 11일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by