two errors : "MEX compiler error" and "Index exceeds the number of array elements"

2 views (last 30 days)
nuri ahn
nuri ahn on 24 Aug 2019
Commented: Guillaume on 24 Aug 2019
Hi all, I am using GPU coder and having problems.
This is my full script.
clear all
%% inputs
load mq % I attached it.
disp('Weights were loaded')
%% Answer
tic;
output_accu=Main2_4_fun(countMax,H1,H2,H3,H4,B1,B2,B3,B4,obsRad,obsCenterX,obsCenterY,minmax,freq_min );
toc;
I tried to make the function "Main2_4_fun" as a MEX file using GPU coder app.
function output_accu_cpu=Main2_4_fun(countMax,H1,H2,H3,H4,B1,B2,B3,B4,obsRad,obsCenterX,obsCenterY,minmax,freq_min )
output_accu = zeros(countMax,1);
minX= minmax(1); maxX= minmax(2); minY= minmax(3); maxY= minmax(4);
obsRad_norm = obsRad; % inputs for Main2_4_fun
obsCenterX_log = (obsCenterX - minX) / (maxX - minX);% inputs for Main2_4_fun
obsCenterY_log = (obsCenterY - minY) / (maxY - minY);% inputs for Main2_4_fun
for caseCount=0:countMax-1 %computing changing input freq_log.
freq_log = log(caseCount + freq_min);
X = transpose([obsRad_norm, obsCenterX_log, obsCenterY_log, freq_log]) ;
%% computing
output_accu(caseCount+1) = transpose(H4{caseCount+1})*max(0,transpose(H3{caseCount+1})*max(0,transpose(H2{caseCount+1})*max(0,transpose(H1{caseCount+1})*X+B1{caseCount+1})+B2{caseCount+1})+B3{caseCount+1})+B4{caseCount+1};
end
output_accu_cpu=output_accu;
end
and I got this error message in the run-time issue check step of MEX file build stage.
??? Unable to determine MEX compiler: use mex -setup to configure your system.
Compilation failed.
Index exceeds the number of array elements (196).
Use help codegen for more information on using this command.
Index exceeds the number of array elements (196).
My version is 2019a, windows 10.
Question 1:
I have installed MinGW-w64 C/C++ Compiler.
But why I got " Unable to determine MEX compiler: " error?
(I also installed Microsoft visual studio 2019, by this two pages. but errors are still not solved.
Quesiton 2:
I started using GPU coder after confirming that my code and function work well.
But why I have "exceeds the number of array elements" error?
I was doing this process even with the same workspace with code execution.
  6 Comments
Guillaume
Guillaume on 24 Aug 2019
There's no need to build X as a row vector and then transpose it, build it directly as a column vector:
X = [obsRad_norm; obsCenterX_log; obsCenterY_log; freq_log];
As Walter said and as I wrote, the tranpose operator is the dotted apostrophe: .', not the plain '. If the numbers are pure real, it makes no difference though.
It's quite difficult to understand what's happening in the computing line as the expression is fairly complex. This also illustrates why it's a bad idea to have numbered variables. If you use indexing instead you can replace the lot by a simple loop.
function output_accu_cpu = Main2_4_fun(countMax, H, B , obs, minmax, freq_min)
%obs: three element vector consisting of obsRad, obscenterX, obsCenterY
%H and B: casecount x 4 cell arrays
%minmax is 4 element vector consisting of maxX, minX, maxY, minY
output_accu_cpu = zeros(countMax 1);
X_base = [obs(1);
(obs(2)-minmax(1)) / (minmax(2)-minmax(1));
(obs(3)-minmax(3)) / (minmax(4)-minmax(3));
];
for casecount = 1:countmax
X = [X_base; log(casecount - 1 + freq_min)];
for col = 1:4
X = max(H{casecount, col}.' * X + B{casecount, col}, 0); %set negative values to 0
end
output_accu_cpu(casecount) = X;
end
end
obviously, you have to change how you call it slightly:
H = [H1, H2, H3, H4];
B = [B1, B2, B3, B4];
obs = [obsRad, obsCenterX, obsCenterY];
output_accu = Main2_4_fun(countMax, H, B, obs, minmax, freq_min);
Now, none of this is going to help with your error. Unfortunately, I don't have the toolbox, so can't help with that. Mathworks even restrict access to the documentation, so I can't even look at that. The 196 is very puzzling, none of your data has that size and 196 is a multiple of 7 and none of your data has size that is a multiple of 7. I think you need to find out where that 196 comes from.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!