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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Jan
Jan el 9 de Jul. de 2019
Editada: Jan el 9 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by