Why do I get "Array indices must be positive integers or logical values." Error
1 view (last 30 days)
Show older comments
Hello,
I've been getting an error, trying to classify a sound. My problem is that when I run my code in Matlab Workspace, it works. However, if I connect to Matlab session in python to run the code, I get this error.
Array indices must be positive integers or logical values.
Error in classify_input (line 13)
my_output = netw(my_input); %input the sample test in the NN
Here's my full matlab code:
function [result] = classify_input(input_location)
global net_stg9; % Previously trained network
netw = net_stg9;
[audioIn, Fs] = audioread(input_location);
my_input = mfcc(audioIn, Fs);
my_input = my_input';
my_input = reshape(my_input, [], 1);
my_output = netw(my_input); %input the sample test in the NN
myClass = max(my_output);
counter = 0;
for i = 1:6
counter = counter + 1;
if (my_output(i, 1) == myClass)
break;
end
end
accuracy = round(myClass * 100);
result = (counter * 1000) + accuracy;
My python code:
matlab_session = matlab.engine.find_matlab()[0]
eng = matlab.engine.connect_matlab(matlab_session)
data = eng.classify_input( './filename1-1.wav');
Any help is appreciated! Thank you.
2 Comments
KSSV
on 15 Dec 2021
I don't think this variable
my_input = my_input';
is not defined in the function.
Accepted Answer
Jan
on 15 Dec 2021
Edited: Jan
on 15 Dec 2021
global net_stg9; % Previously trained network
netw = net_stg9;
my_output = netw(my_input);
netw seems to be an array, not a trained network. The problem with global variables is, that they impede debugging massively. So it might be hard to find out, which function has overwritten the network by an array.
Check the contents of this variable using the debugger:
dbstop if error
Run the code again until Matlab stops at the error. Then inspect the contents of netw.
0 Comments
More Answers (0)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!