How do I create a linear function of cells from a cell array?

조회 수: 1 (최근 30일)
Philipp Deutscher
Philipp Deutscher 2019년 1월 3일
답변: Sachin Meena 2019년 1월 7일
As seen below, I can't convert my cell array into a function:
% Profilverschiebung:
m_1 = 1
m_1 = 1
alpha1 = 14 * pi/180;
invalpha1 = tan(alpha1) - alpha1;
invalpha_w1 = @(x1) 2*(x1(1)+x1(2))*tan(alpha1) / (z(1)+z(2)) + invalpha1;
alpha_w1 = @(x1) (3*invalpha_w1)^(1/3) - 2/5*invalpha_w1;
d_w1 = cell(3,1);
n = 3;
k=0;
for i = 1:n
d_w1{i} = @(x1) z_gewaehlt(i)*m_1 * cos(alpha1)/cos(alpha_w1)
end
d_w1 = 3×1 cell array
{@(x1)z_gewaehlt(i)*m_1*cos(alpha1)/cos(alpha_w1)}
{0×0 double }
{0×0 double }
d_w1 = 3×1 cell array
{@(x1)z_gewaehlt(i)*m_1*cos(alpha1)/cos(alpha_w1)}
{@(x1)z_gewaehlt(i)*m_1*cos(alpha1)/cos(alpha_w1)}
{0×0 double }
d_w1 = 3×1 cell array
{@(x1)z_gewaehlt(i)*m_1*cos(alpha1)/cos(alpha_w1)}
{@(x1)z_gewaehlt(i)*m_1*cos(alpha1)/cos(alpha_w1)}
{@(x1)z_gewaehlt(i)*m_1*cos(alpha1)/cos(alpha_w1)}
Geometriebedingung_Planetenstufe = @(x1) d_w1{1} + 2 * d_w1{2} + d_w1{3};
x1_0 = [0 0 0]
x1_0 = 1×3
0 0 0
x1 = fminsearch(Geometriebedingung_Planetenstufe, x1_0)
And thats my error log:
Undefined operator '*' for input arguments of type 'function_handle'.
Error in Berechnung_Zaehnezahlen_und_Profilverschiebung_MEL_KU_2>@(x1)d_w1{1}+2*d_w1{2}+d_w1{3}
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});

답변 (1개)

Sachin Meena
Sachin Meena 2019년 1월 7일
The error arises as you are trying to multiply a function handle with scalar 2. The content of your cell array d_w1 are function handles that take a single argument as input. While using them in defining "Geometriebedingung_Planetenstufe", you are not providing these handles any input, hence the error. I am not sure as to what you wish to achieve, but you probably wish to do this.
Geometriebedingung_Planetenstufe = @(x1) d_w1{1}(x1) + 2 * d_w1{2}(x1) + d_w1{3}(x1);

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by