Function does not return all declared outputs

9 visualizzazioni (ultimi 30 giorni)
The following function has three declared outputs. Although each output is correctly calculated, function returns only output variable #1 in the row (verified by changing position of the variables), like there would be only one output variable declared.
----
function [rRollAltAgl, rPitchAltAgl, rRollIas] = evRisk(raw_vector)
%raw_vector = input(prompt);
roll = raw_vector(1);
pitch = raw_vector(2);
ias = raw_vector(3);
altAGL = raw_vector(4);
% ----rRoll_AltAGL Calculation
rRollAltAgl = evalfis(fisStructRoll_AltAGL,[roll altAGL]);
% ----rPitch_AltAGL Calculation
rPitchAltAgl = evalfis(fisStructPitch_AltAGL,[pitch altAGL]);
% ----rRoll_IAS Calculation
% Roll_IAS Excess Over Stall
rollRad = roll*(pi/180); % bank in degrees to radians
GInc = sec(rollRad); % load increase (roll secans)
stallIAS = 72; % stall speed clean config
stallInc = stallIAS * sqrt(GInc); % stall speed increase
iasExc = ias/stallInc; % excess of speed over stall speed
rollIASOutput = (iasExc-1)*100; % value for calculations
% Roll_IAS Risk Assement
if rollIASOutput > 50
rRollIas = 10;
elseif rollIASOutput > 45
rRollIas = 20;
elseif rollIASOutput > 40
rRollIas = 30;
elseif rollIASOutput > 35
rRollIas = 40;
elseif rollIASOutput > 30
rRollIas = 50;
elseif rollIASOutput > 25
rRollIas = 60;
elseif rollIASOutput > 20
rRollIas = 70;
elseif rollIASOutput > 15
rRollIas = 80;
else
rRollIas = 90;
end
end
function Roll_AltAGL_4C = fisStructRoll_AltAGL(~)
Roll_AltAGL_4C = getFISCodeGenerationData('Roll_AltAGL.fis');
end
function Pitch_AltAGL_4C = fisStructPitch_AltAGL(~)
Pitch_AltAGL_4C = getFISCodeGenerationData('Pitch_AltAGL.fis');
end
  4 Commenti
Walter Roberson
Walter Roberson il 21 Giu 2021
You can zip other kinds of files and attach the .zip

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 21 Giu 2021
risk_calc = evRisk(raw_vector)
That requests that the first (positional) output be assigned to risk_calc and that any other outputs be discarded.
Remember that MATLAB only ever assigns positionally (though syms arguably violates that). If you have a function
function [A, B, C] = whatever()
and the function call does not have three outputs, then MATLAB will not assign to B and C inside the calling function: it will just discard those outputs.
MATLAB also does not bundle all of the outputs into a single cell array. In the above case, it is not going to check whether three outputs were asked for and if so assign the correspondingly, but if only one output were asked for then put the three outputs into a cell array and assign that -- that sort of thing is never done.
If you want three outputs, then assign to three variables.
[risk_calc, rPa, rPi] = evRisk(raw_vector);

Più risposte (0)

Categorie

Scopri di più su Scope Variables and Generate Names in Help Center e File Exchange

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by