output argument not assigned during call

4 ビュー (過去 30 日間)
Robert Tapia
Robert Tapia 2020 年 6 月 30 日
コメント済み: Prateek Tiwari 2020 年 6 月 30 日
this is part of the code but i get an error that " output argument J not assigned during call" can anyone help me see where im messing up
K = linspace(-20.5,13,501);
UpperBound = 1;
LowerBound = 0;
J = MYFunction(K)
function J = MYFunction(x)
N = length(x);
for n = 1:N
if x(n) <= -5.5
y(n) = .2.*x(n) + 4.1;
end
if (x(n) > -5.5 & x(n) <= 5.5)
y(n) = .08.*x(n).^2 + 5.42;
end
if x(n) > 5.5
y(n) = -.4.*x(n) + 5.2;
end
end

採用された回答

Image Analyst
Image Analyst 2020 年 6 月 30 日
Probably your y is supposed to be your J
K = linspace(-20.5,13,501);
UpperBound = 1;
LowerBound = 0;
J = MYFunction(K)
function J = MYFunction(x)
J = x; % Initialize.
y = x;
N = length(x);
for n = 1:N
if x(n) <= -5.5
y(n) = .2.*x(n) + 4.1;
end
if (x(n) > -5.5 & x(n) <= 5.5)
y(n) = .08.*x(n).^2 + 5.42;
end
if x(n) > 5.5
y(n) = -.4.*x(n) + 5.2;
end
end
% Assign output y ==> J
J = y;
Not sure why you create UpperBound and LowerBound -- they aren't used anywhere.
  1 件のコメント
Robert Tapia
Robert Tapia 2020 年 6 月 30 日
oh the upperbound/lowerbound are used for a while loop i just didnt include it since i dont think it mattered for the error i was getting

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 6 月 30 日
Where in your MYFunction function do you assign any value to the variable J?
  2 件のコメント
Robert Tapia
Robert Tapia 2020 年 6 月 30 日
we weren't given any values to assign to J, professor just has " define: J = MYFunction(K)" and to calculate the values for it
Prateek Tiwari
Prateek Tiwari 2020 年 6 月 30 日
Hi @ Steven
Can you please help me with this,
https://nl.mathworks.com/matlabcentral/answers/557005-calling-a-function-in-matlab-function-block-in-simulink?s_tid=prof_contriblnk

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

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by