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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by