Function doesn't return a vector from a vector input
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Leonardus Yudha Septian Sutanto
le 15 Nov 2019
Commenté : Star Strider
le 15 Nov 2019
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?
0 commentaires
Réponse acceptée
Star Strider
le 15 Nov 2019
‘Could someone tell me my mistake?’
if any(Ffork0+Inc_Ffork*t <= Ffork_max)
Ffork=Ffork0+Inc_Ffork*t;
elseif any(Ffork0+Inc_Ffork*t > Ffork_max)
Ffork = Ffork_max;
end
2 commentaires
Plus de réponses (1)
dpb
le 15 Nov 2019
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
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!