Output argument "px" (and maybe others) not assigned during call to "function1"

1 回表示 (過去 30 日間)
ParkerCambridge
ParkerCambridge 2019 年 7 月 9 日
編集済み: Jan 2019 年 7 月 9 日
Hi,
I am fairly acquainted with matlab, however failing to understand the output error I am getting from the following function.
function [px, b, c, d ,mse, varx] = function1 (x, y, h, i, j, k, l)
somecode
% Design Matrix
Des_mat = X;
while varx >= tol
somecode
b = vector;
w_mat = w;
c = w_mat;
d = scalervalue;
[px,~,mse] = lscov(Des_mat,yn,w_mat.^2); % Evaluate lscov
varx = 1.2; % some value
somecode;
end
end
When this function is called in a for loop as
for l=1:k
somecode;
[px, b, c, d ,mse, varx] = function1 (x, y, h, i, j, k, l);
somecode;
end
It gives following error
Output argument "px" (and maybe others) not assigned during call to "function".
Surprisingly, the function
function1
runs for first 47 iterations. However, it fails to run afterwards. Can someone help and explain despite px being assigned why it is failing to execute?
Many Thanks

採用された回答

Jan
Jan 2019 年 7 月 9 日
編集済み: Jan 2019 年 7 月 9 日
If the initial value of varx is smaller than tol already, the body of the while varx>=tol loop is not entered at all. Then e.g. px is not defined. Add a test of this condition:
if varx < tol
error('Unexpected initial value');
end
while varx >= tol
...
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by