Hi, How can I resolve this error message, please "Array indices must be positive integers or logical values" Below are my lines of code:

2 views (last 30 days)
perfs = zeros(1, numNN); y2Total = 0; for i = 1:numNN neti = nets{i}; y2 = neti(x2); perfs(i) = mse(neti, t2, y2); y2Total = y2Total + y2; end perfs y2AverageOutput = y2Total / numNN; perfAveragedOutputs = mse(nets{1}, t2, y2AverageOutput)

Accepted Answer

John D'Errico
John D'Errico on 5 Jun 2018
Edited: John D'Errico on 5 Jun 2018
This is why it is always important to read the ENTIRE error message, as that will tell you much. And if you don't understand the message, then show the complete message when you ask a question.
Here I see several possible reasons why you may have generated that message. It will arise whenever you do an index operation where the index variable is not of the proper form. But sometimes the reason for this is not obvious.
So, looking at your code, I see this operation: zeros(1,numNN). Could that be the cause? try this:
numNN = 5.2;
So, now, if I do this:
zeros(1,numNN)
Error using zeros
Size inputs must be integers.
then I get an error, but a different error. But, suppose I had done this terribly bad thing before?
zeros = 1:12;
As I said, that is a REALLY BAD idea. But suppose you had done so? So suppose I had created a variable with the name zeros? Now try it:
zeros(1,numNN)
Subscript indices must either be real positive integers or logicals.
'zeros' appears to be both a function and a variable. If this is unintentional, use 'clear zeros' to remove the variable 'zeros' from the workspace.
So here we get the error message you found. Is that what caused your problem? Perhaps. Or perhaps not.
Later on, I see:
y2 = neti(x2);
Could that be the cause of your error? Perhaps. If neti is a variable, and x2 a number that is not an integer or a boolean vector, then it would generate that basic error message. In fact, we see that neti IS a variable, since you defined it just before that point, as
neti = nets{i};
So what is x2? That we cannot know, since you have not told us.
We can continue on. Could mse be a variable? Might you have created a variable named mse? Who knows? Well, you should know.
And the error message would have helped you to understand where the problem arose, just as the example error message I posted above tells me the problem was in zeros when I did that.
(If I had to hazard a completely wild guess, I'd bet that x2 is not a positive integer. Just a wild guess though.)

More Answers (1)

Image Analyst
Image Analyst on 5 Jun 2018

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!