Index exceeds number of array elements (1)?
Show older comments
This is the code on derivada.m:
function [Hd] = derivada(valores, h)
i = 2;
while i < length(valores)
Hd(i) = (valores(i+1) - valores(i-1))/(2 * h);
i = i+1;
end
Hd(1) = ((valores(2) - valores(1))/h);
Hd(length(valores)) = (valores(length(valores)) - valores(length(valores)-1))/h;
end
And this is the main:
valores = y;
h = 0.1;%t(2) - t(1);
Hd = derivada(valores, h);
This is the error:
Index exceeds number of array elements (1)

Answers (1)
Cris LaPierre
on 9 Jan 2021
0 votes
It would appear valores only has a single value, yet you are trying to index a second.
Categories
Find more on Matrix Indexing 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!