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

1 view (last 30 days)
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:
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. :)

Answers (4)

Image Analyst
Image Analyst on 1 Apr 2017
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:
Image Analyst
Image Analyst on 6 Apr 2017
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));
And please attach this file: 'C:\xampp\htdocs\Test\testx.txt' with the paper clip icon.

Sign in to comment.

Steven Lord
Steven Lord on 1 Apr 2017
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 =;
AshM on 6 Apr 2017
This is the trained neural network file. If anybody can try it out and help me figure out this error, I will be grateful.

Sign in to comment.

Greg Heath
Greg Heath on 7 Apr 2017
Nowhere is 'net' defined.
Hope this helps.

Sean de Wolski
Sean de Wolski on 4 Aug 2021

Community Treasure Hunt

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

Start Hunting!