function sf =aaa(u) | Error: Function definitions are not permitted in this context.

21 ビュー (過去 30 日間)
Himanshu
Himanshu 2014 年 4 月 26 日
回答済み: Star Strider 2014 年 4 月 26 日
%Matlab Code to generate Switching functions
% Inputs are magnitude u1(:),angle u2(:)
% and ramp time signal for comparison u3(:)
function sf =aaa(u)
ts=0.0002;vdc=1;peak_phase_max= vdc/sqrt(3);
x=u(2); y=u(3); mag=(u(1)/peak_phase_max) * ts;
%sector I
if (x>=0) & (x<pi/3) ta = mag * sin(pi/3-x);tb = mag * sin(x); t0 =(ts-ta-tb);
t1=[t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4];t1=cumsum(t1);
v1=[0 1 1 1 1 1 0];v2=[0 0 1 1 1 0 0];v3=[0 0 0 1 0 0 0];
for j=1:7
if(y<t1(j))
break
end
end
sa=v1(j);sb=v2(j);sc=v3(j);
end
% sector II
if (x>=pi/3) & (x<2*pi/3) adv= x-pi/3;
tb = mag * sin(pi/3-adv);ta = mag * sin(adv);
t0 =(ts-ta-tb);
t1=[t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4];t1=cumsum(t1);
v1=[0 0 1 1 1 0 0];v2=[0 1 1 1 1 1 0];v3=[0 0 0 1 0 0 0];
for j=1:7
if(y<t1(j))
break
end
end
sa=v1(j);sb=v2(j);sc=v3(j);
end
%sector III
if (x>=2*pi/3) & (x<pi) adv=x-2*pi/3;
ta = mag * sin(pi/3-adv);tb = mag * sin(adv);
t0 =(ts-ta-tb);
t1=[t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4];t1=cumsum(t1);
v1=[0 0 0 1 0 0 0];v2=[0 1 1 1 1 1 0];v3=[0 0 1 1 1 0 0];
for j=1:7
if(y<t1(j))
break
end
end
sa=v1(j);sb=v2(j);sc=v3(j);
end
%sector IV
if (x>=-pi) & (x<-2*pi/3) adv = x + pi;
tb= mag * sin(pi/3 - adv);ta = mag * sin(adv);
t0 =(ts-ta-tb);
t1=[t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4];t1=cumsum(t1);
v1=[0 0 0 1 0 0 0];v2=[0 0 1 1 1 0 0];v3=[0 1 1 1 1 1 0];
for j=1:7
if(y<t1(j))
break
end
end
sa=v1(j);sb=v2(j);sc=v3(j); end
% sector V
if (x>=-2*pi/3) & (x<-pi/3) adv = x+2*pi/3;
ta = mag * sin(pi/3-adv);tb = mag * sin(adv);
t0 =(ts-ta-tb); t1=[t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4];t1=cumsum(t1);
v1=[0 0 1 1 1 0 0];v2=[0 0 0 1 0 0 0];v3=[0 1 1 1 1 1 0];
for j=1:7 if(y<t1(j)) break end
end sa=v1(j);sb=v2(j);sc=v3(j);
end
%Sector VI
if (x>=-pi/3) & (x<0) adv = x+pi/3;
tb = mag * sin(pi/3-adv);ta = mag * sin(adv);
t0 =(ts-ta-tb);
t1=[t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4];t1=cumsum(t1);
v1=[0 1 1 1 1 1 0];v2=[0 0 0 1 0 0 0];v3=[0 0 1 1 1 0 0];
for j=1:7
if(y<t1(j))
break
end
sa=v1(j);sb=v2(j);sc=v3(j);
end
end
sf=[sa, sb, sc];

採用された回答

Star Strider
Star Strider 2014 年 4 月 26 日
You are only allowed to have a function statement (except for anonymous and inline functions) inside another function file so:
function x = fun(y)
.
.
function sf =aaa(u)
.
.
end
end
is permitted, but
first line of my script file
.
.
function sf =aaa(u)
.
.
end
is not.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by