I would like to create a handle function by for loop in matlab, but it does not work. I will be thankful if some body help me.
조회 수: 1 (최근 30일)
이전 댓글 표시
a=[1 2 3];
b=[4 5 6]
n=length(a);
for i=1:n
s(i)=@(x) a(i)*x-b(i)*x;
end
댓글 수: 0
답변 (2개)
Chunru
2021년 10월 23일
a=[1 2 3];
b=[4 5 6]
n=length(a);
for i=1:n
s{i}=@(x) a(i)*x-b(i)*x;
end
s{1}(3)
댓글 수: 0
Alan Stevens
2021년 10월 23일
편집: Alan Stevens
2021년 10월 23일
More like this?
sfn = @(x,a,b) (a - b)*x;
a=[1 2 3];
b=[4 5 6];
n=length(a);
x = 1; % specify whatever x value you want
for i=1:n
s(i) = sfn(x,a(i),b(i));
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Electrical Block Libraries에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!