how do I store an array of functions?

조회 수: 131 (최근 30일)
Krishna Beemanapalli
Krishna Beemanapalli 2020년 5월 8일
댓글: Stephen23 2020년 5월 8일
I want to store the following function for i=0:170
f = @(u) 2/(pi*sqrt(1-((sin(i/2)^2)*(sin(u)^2))));
and evaluate using my function.
  댓글 수: 1
Stephen23
Stephen23 2020년 5월 8일
What is the point in creating 171 copies of (almost) the same function, when you can just create one?:
f = @(u,i) 2/(pi*sqrt(1-((sin(i/2)^2)*(sin(u)^2))));

댓글을 달려면 로그인하십시오.

답변 (2개)

per isakson
per isakson 2020년 5월 8일
편집: per isakson 2020년 5월 8일
An error message tells me
Nonscalar arrays of function handles are not allowed; use cell arrays instead.
Is this what are looking for?
>> f{1}(pi/2)
ans =
0.63662
>> f{100}(pi/2)
ans =
0.88291
>>
where f is created by
%%
f = cell( 1, 171 );
for ii = 0 : 170
f{ii+1} = @(u) 2/(pi*sqrt(1-((sin(ii/2)^2)*(sin(u)^2))));
end
Or why not
%%
f3 = @(u,jj) 2./(pi*sqrt(1-((sin(jj/2).^2).*(sin(u).^2))));
f3(pi/2,0)

KSSV
KSSV 2020년 5월 8일
i = 0:170 ;
f = @(u) 2./(pi*sqrt(1-((sin(i/2).^2).*(sin(u).^2))));
f = f(i) ;
plot(i,f)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by