Function handle

조회 수: 4 (최근 30일)
Anastasia
Anastasia 2012년 5월 20일
Hi!
I need to create a cell containing a set of functions of ascending degree, that is: 1,x,x^2,...,x^n, to be used in another function. I have to transform the code:
fhandles = {@(x)ones(length(x),1), @(x)x, @(x)x.^2};
in a generic one where the degree is n (and not 2), where n is an input parameter of the main function. Can you please help me?

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 5월 20일
fhandles = @(n)cellfun(@str2func,cellstr(strcat('@(x)x.^',num2str((0:n)'))),'un',0)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by