Function does not return all declared outputs

9 ビュー (過去 30 日間)
Artur Bogdanowicz
Artur Bogdanowicz 2021 年 6 月 21 日
編集済み: Artur Bogdanowicz 2021 年 6 月 21 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 6 月 21 日
You can zip other kinds of files and attach the .zip
Artur Bogdanowicz
Artur Bogdanowicz 2021 年 6 月 21 日
Of course! Here they are.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 21 日
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);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by