Function doesn't return a vector from a vector input
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Leonardus Yudha Septian Sutanto
il 15 Nov 2019
Commentato: Star Strider
il 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 Commenti
Risposta accettata
Star Strider
il 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 Commenti
Più risposte (1)
dpb
il 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
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!