Why do I get "Array indices must be positive integers or logical values." Error
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.
Semih Yönet
on 15 Dec 2021
Accepted Answer
More Answers (0)
Categories
Find more on Reinforcement Learning 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!