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

1 view (last 30 days)
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

Accepted Answer

Jan
Jan on 9 Jul 2019
Edited: Jan on 9 Jul 2019
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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!