My code runs as a m file but not as an exe. What to do?

조회 수: 3 (최근 30일)
AshM
AshM 2017년 4월 1일
답변: Sean de Wolski 2021년 8월 4일
The code runs perfectly well in Matlab, however, when I compile an exe file and run that, it gives me the following error:
"subscript indices must either be real positive integers or logicals"
The code is as follows:
face=faceDetect();
dEye=eyeDistance(face);
[dh,dv,A]=mouthDistance(face);
dEyebrow=eyebrowDistance(face);
[f,n]=wrinkles(face);
x=[];
x(1,1)=dEye
x(1,2)=dEyebrow
x(1,3)=dh
x(1,4)=dv
x(1,5)=A
x(1,6)=f
x(1,7)=n
x=transpose(x);
load ('C:\xampp\htdocs\Test\Final\trained_net_3lm.mat');
dlmwrite('C:\xampp\htdocs\Test\testx.txt', x);
y=net(x); %*** HERE ***
dlmwrite('C:\xampp\htdocs\Test\test.txt', y);
The line marked HERE is the one throwing out the error.
Help would be really appreciated. :)

답변 (4개)

Image Analyst
Image Analyst 2017년 4월 1일
I guess net is one of your arrays. So I'd guess that one of the elements of x is either zero, a negative number, or a fractional value. Type out x before you use it. See the FAQ on this extremely frequently asked question: http://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F
  댓글 수: 2
AshM
AshM 2017년 4월 3일
I think it shouldn't matter what are the contents of the array x as long as the indices are not either negative or zero or floating point number. And even so, the code runs perfectly well in matlab as a .m file but it gives the error mentioned above when ran as an exe file
Image Analyst
Image Analyst 2017년 4월 6일
Please add these lines before the net(x) line and tell us what you see in the console window:
for k = 1 : length(x)
fprintf('x(%d) = %f\n', k, x(k));
end
And please attach this file: 'C:\xampp\htdocs\Test\testx.txt' with the paper clip icon.

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2017년 4월 1일
I suspect net is an object created using Neural Network Toolbox functions that you loaded from the MAT-file. If so realize that without some indication MATLAB Compiler can detect via static analysis of your code, it has no way of knowing that it needs to include the functionality from Neural Network Toolbox in your application. You'll need to use the %#function pragma to give it that hint. See in particular the documentation topic linked in Example 3 on that page.
I'd also consider calling load with an output argument rather than just "poofing" the variable into the workspace. Use something like:
mydata = load(...);
y = mydata.net(x);
  댓글 수: 3
Steven Lord
Steven Lord 2017년 4월 3일
Attach the MAT-file C:\xampp\htdocs\Test\Final\trained_net_3lm.mat to this Answer so people can try it out. If that's not possible or you'd prefer not to do that, send the MAT-file along with this question to Technical Support.
AshM
AshM 2017년 4월 6일
This is the trained neural network file. If anybody can try it out and help me figure out this error, I will be grateful.

댓글을 달려면 로그인하십시오.


Greg Heath
Greg Heath 2017년 4월 7일
Nowhere is 'net' defined.
Hope this helps.
Greg

Sean de Wolski
Sean de Wolski 2021년 8월 4일

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by