フィルターのクリア

Output argument not assigned during call

8 ビュー (過去 30 日間)
Joe
Joe 2013 年 4 月 3 日
I get this error message when I try to run a function that I created. I understand what this is saying, but when I look at my function, the output argument is already correctly defined within the function. So what else could be wrong?
Here is the function:
function y = linInt(xData,yData,x)
if x < xData(1) || x > xData(end)
error('values in x out of range')
else
for i = 1:x
y(i) = yData(i) + ((yData(i+1)-yData(i))*(x-xData(i))/(xData(i+1)-xData(i)));
end
end
end

採用された回答

Walter Roberson
Walter Roberson 2013 年 4 月 3 日
When the code executes, for some reason the statement that assigns a value to the output variable is not being reached. This can happen due to logic errors in how the code was written.
You could post the code for us to examine, or you could use the debugger to trace the flow of the code.
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 4 月 3 日
Your code
for i = 1:x
should be
for i = 1 : length(xData)
Remember, your provided x could be negative.

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

その他の回答 (1 件)

Alexandra
Alexandra 2013 年 4 月 3 日
You only assign an output value for y, if the else-branch is executed. You also need to assign a value for y for the if-branch. E.G.
if ...
y = [];
else
y = ...;
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by