MATLAB Error: Array Indices must be positive or logical values
Show older comments
h=input('Enter estimate for root');
f=(h^3)-(9*(h^2))+3.8197;
fprime=(3*(h^2))-(18*h);
for i=1:10
h=h(i)+abs((f(h))/(fprime(h)));
end
2 Comments
Adam
on 29 Mar 2019
You either want to create f and fprime as function handles to use the syntax you use, which seems un-necessary here, or just get rid of the (h) from within the for loop:
for i=1:10
h=h(i)+abs(f/fprime);
end
madhan ravi
on 29 Mar 2019
Shot in the dark:
h=input('Enter estimate for root');
f=@(h)(h^3)-(9*(h^2))+3.8197;
fprime=@(h)(3*(h^2))-(18*h);
for i=1:10
h=h+abs((f(h))/(fprime(h)));
end
Accepted Answer
More Answers (1)
Preksha Gupta
on 20 May 2022
0 votes
load Meter1Cor.txt
XTest= Meter1Cor(:, 2:10);
YTest= Meter1Cor(:,11);
XTest=XTest';
YTest= YTest';
load one
y=one(XTest)
error=y-YTest;
plot(error,'g')
title("Error");
xlabel("Epochs");
ylabel("Error");
This is for testing a trained neural network. "one" is name of trained neural network and i am receiving an error stating that "array indices must be positive intergers or logical values." What could be a possible mistake i made?
1 Comment
Walter Roberson
on 20 May 2022
XTest= Meter1Cor(:, 2:10);
That creates a 2d array that would not typically be restricted to positive integers.
load one
y=one(XTest)
You load a variable and then you try to index it using linear indices whose values are the contents of XTest. That requires that XTest either be empty or be all positive integers.
Categories
Find more on Loops and Conditional Statements 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!