Looping question
8 次查看(过去 30 天)
显示 更早的评论
Hi, I have a question regarding using loop for a function file. For example, let func represent a function file, where f = x^2 - 1 and f is the output argument and x is the input argument.
Now, my x = 1:100. and now for i = 1:100 z(i) = func(x(i)); end
f_n = min(f).
My question: Is there a way where I can identify the particular x for which f_n is giving out the value for?
Thanks, Mahesh Ramaraj.
0 个评论
采纳的回答
Sean de Wolski
2011-3-9
No reason for loops!
x = 1:100; %x vector
func = @(x)x.^2-1; %function to apply
[the_min, idx] = min(func(x)); %find the minimum and index of minimum
min_x = x(idx); %extract x corresponding to the minimum of f(x)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!