How do I refer to the next y point in a function?
5 次查看(过去 30 天)
显示 更早的评论
say I have y = f(x), how can I refer to the next point in y(a+1) = f(x+1) with only using y in my code?
Thank you! :)
0 个评论
采纳的回答
KSSV
2021-11-24
You need to define x as an array, when you sustitue x in the function f, you will get output array y which is of same dimension like x. And after you can index.
EXamples:
f = @(x) sin(x) ;
x = linspace(0,2*pi) ;
y = f(x) ;
plot(x,y)
for i = 1:10
[x(i) y(i)]
end
If you are planning to use a loop (to learn).
f = @(x) sin(x) ;
x = linspace(0,2*pi) ;
y = f(x) ;
n = length(x) ;
y = zeros(1,n) ;
for i = 1:n
y(i)= f(x(i)) ;
end
plot(x,y)
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!