Function doesn't return a vector from a vector input
이전 댓글 표시
function Ffork = Fforkfase3(t)
Feff=35; %Load applied by the driver at the shift lever [N], Maximum value allowed: 180-250 N
Feff_max=90; %Max effort applied by the driver [N]
eff=0.6; %Efficiency of the shift mechanism (normally <70%)
TR=7; %Transmission ratios of the shift mechanism (Normally varies between 7:1 and 12:1)
Ffork0=Feff*eff*TR; %Load on the sleeve [N]
Ffork_max=Feff_max*eff*TR; %Max load on the sleeve [N]
Inc_Ffork=(Ffork_max-Ffork0)/0.2;
if Ffork0+Inc_Ffork*t <= Ffork_max
Ffork=Ffork0+Inc_Ffork*t;
elseif Ffork0+Inc_Ffork*t > Ffork_max
Ffork = Ffork_max;
end
end
Hi,
I have a function with a distinction of cases. The force Ffork should be constant once it reached the maximum value, as you can see in the code.
The input t should be a vector, I called the function in this way:
t=0.08:0.01:0.2727
Ffork = Fforkfase3(t)
I would like to get a vector of Ffork as output. However, I got an error message after running it:
Output argument "Ffork" (and maybe others) not assigned during call to "Fforkfase3".
Could someone tell me my mistake?
채택된 답변
추가 답변 (1개)
dpb
2019년 11월 15일
Yes, you didn't read about logical IF
if Ffork0+Inc_Ffork*t <= Ffork_max
is True iff every element of Ffork0+Inc_Ffork*t is <= Ffork_max and similarly for the eseif clause. The upshot is your code didn't pass either test and so the if clause was never executed.
However, "the MATLAB way" doesn't need the if clause anyways; use the vector nature...
function Ffork = Fforkfase3(t)
Feff=35; %Load applied by the driver at the shift lever [N], Maximum value allowed: 180-250 N
Feff_max=90; %Max effort applied by the driver [N]
eff=0.6; %Efficiency of the shift mechanism (normally <70%)
TR=7; %Transmission ratios of the shift mechanism (Normally varies between 7:1 and 12:1)
Ffork0=Feff*eff*TR; %Load on the sleeve [N]
Ffork_max=Feff_max*eff*TR; %Max load on the sleeve [N]
Inc_Ffork=(Ffork_max-Ffork0)/0.2;
Ffork=min(Ffork0+Inc_Ffork*t,Ffork_max);
end
카테고리
도움말 센터 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!