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

1 vue (au cours des 30 derniers jours)
ParkerCambridge
ParkerCambridge le 9 Juil 2019
Modifié(e) : Jan le 9 Juil 2019
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

Réponse acceptée

Jan
Jan le 9 Juil 2019
Modifié(e) : Jan le 9 Juil 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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by