error in embedded matlab function

2 次查看(过去 30 天)
studentU
studentU 2015-4-28
评论: studentU 2015-4-30
hi, i have 3 function.m, i use it to develop embedded matlab-function , But it generates this error:
>> Undefined function or method 'fnct1' for input arguments of type'double'
what is the causes? and how can i resolve this error? thanks.

回答(3 个)

pfb
pfb 2015-4-28
编辑:pfb 2015-4-28
Matlab is complaining because it cannot find fnct1. This is the typical answer you get when you use a function that does not exist. Just type
nonexistentfunction(42.0)
I assume that fnct1 is the name of one of your functions.
Where and how do you define that function?
You mention .m files. Is the fnct1.m file in your working directory, or anywhere in matlab known path?
  4 个评论
studentU
studentU 2015-4-29
it's just that program content is too long ...!
so:
%%funct1.m
function [az, el, de, ho] = fnct1 (ta, tm, tj, th, ti, ts, lo, la, orl, al, ut)
%%...
az = ta + tm;
el = th + ti + tj;
de = lo- ts;
ho = la+orl-ut *al ;
end
%%funct2.m
function [in] = fnct2 (el, az, the paragraph, from, ho)
syms in
in=solve('[sin(la)*sin(de)+cos(hor)]*cos(in)-[cos(al)*sin(de)*cos(la)+cos(de)*sin(al)*sin(hor)]*sin(in)=1');
end
%%funct3.m
function [or] = fnct3 (el, az, in)
syms or
or = solve ('[cos (in) * sin (el) - [sin (b) * cos (e) * cos (az)] * cos (or) - [sin (az) * sin (in) * cos (e)] * sin (or) = 1 ');
end
%%in blocks embedded matlab-function,
function [Cor, Cin] = fnct4 (ta, tm, tj, th, ti, ts, lo, orl,la, al, ut)
coder.extrinsic('fminbnd');
coder.extrinsic('matlabfunction');
coder.extrinsic('fcnt1')
coder.extrinsic('fcnt2')
coder.extrinsic('fcnt3')
[az, el, de, ho] = fnct1 (ta, tm, tj, th, ti, ts, lo, la, orl, al, ut)
fin=matlabfunction(fnct1);
Imin=degtorad(0);
Imax=degtorad(90);
Cin = fminbnd(fin, Imin, Imax)
fori=matlabfunction(fcnt3);%hundl function
Omin=degtorad(-90);
Omax=degtorad(90);
Cor = fminbnd(fori, Omin, Omax)
end
the function.m is save in the working repertory, and i simulate just the matlab function block. i hope that is clear now! thanks for ure coordination.
pfb
pfb 2015-4-29
编辑:pfb 2015-4-29
Uhm, I see that you define fnct1 (in fnct1.m, if I get it right) but then you feed 'fcnt1' into coder.extrinsic.
Same bunch of letters, different order :)
You mistyped "fcnt1" instead of "fnct1".
I guess that's why matlab is complaining.

请先登录,再进行评论。


studentU
studentU 2015-4-29
编辑:studentU 2015-4-29
i'm sorry, i was wrong, but it generate the sme error!!!!
  1 个评论
pfb
pfb 2015-4-29
you should pay more attention if you want other people's help.
Why did you answer your own question instead of my comment now? This produces even more confusion!
Are you sure there are no typos in the argument of coder.extrinsic? Are you sure that you used the single quotes?
I'm not sure of anything now, since what you pasted is not really your code...

请先登录,再进行评论。


studentU
studentU 2015-4-29
编辑:studentU 2015-4-30
Here it is my program with some reduction but the point is that, I just tried to simplify your understanding, but it appears that I commit typos ....
%%funct1.m
function [az, el, de, ho] = fnct1 (ta, tm, tj, th, ti, ts, lo, la, orl, al, ut)
%%...
az = ta + tm; el = th + ti + tj; de = lo- ts; ho = la+orl-ut *al ;
end
%% funct2.m
function [in] = fnct2 (el, az, the paragraph, from, ho)
syms in
in=solve('[sin(la)*sin(de)+cos(hor)]*cos(in)- [cos(al)*sin(de)*cos(la)+cos(de)*sin(al)*sin(hor)]*sin(in)=1');
end
%% funct3.m
function [or] = fnct3 (el, az, in)
syms or
or = solve ('cos (in) * sin (el) - [sin (b) * cos (e) * cos (az)] * cos (or) -
[sin (az) * sin (in) * cos (e)] * sin (or) = 1 ');
end
%%in blocks embedded matlab-function,
function [Cor, Cin] = fnct4 (ta, tm, tj, th, ti, ts, lo, orl,la, al, ut)
coder.extrinsic('fminbnd');
coder.extrinsic('matlabfunction');
coder.extrinsic('fnct1')
coder.extrinsic('fnct2')
coder.extrinsic('fnct3')
[az, el, de, ho] = fnct1 (ta, tm, tj, th, ti, ts, lo, la, orl, al, ut)
fin=matlabfunction(fnct1);
Imin=degtorad(0);
Imax=degtorad(90);
Cin = fminbnd(fin, Imin, Imax)
fori=matlabfunction(fcnt3);%hundl function
Omin=degtorad(-90);
Omax=degtorad(90);
Cor = fminbnd(fori, Omin, Omax)
end
thank's for your patience
  4 个评论
pfb
pfb 2015-4-30
Not easy to single out the error, given your sloppy way of presenting things. For instance, the line you pasted above
%%funct1.m function [az, el, de, ho] = fnct1 (ta, tm, tj, th, ti, ts, lo, la, orl, al, ut) %%...
looks like you commented the first line the code of your function. That would turn it into a script. Or even give you errors because of the "end".
But I do not know, because you do not bother to be clear.
studentU
studentU 2015-4-30
for lack of space, I have a concern to past the comments correctly. but be sure that typos do not occur in the program.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by