unassigned variable during loop execution of a function
古いコメントを表示
Hello everyone;
I have the following function: [sum_Power,Lambda,exitflag,sum_rate]=Global_MAX_EE(N0,nbr_R,h_j,h_ij,Sc,P_j,ep,r_j,ub,P_max);
I need to execute this function almost 200 or 300 times. However, as soon as I start the execution I get the following error: Output argument "sum_Power" (and maybe others) not assigned during call to "Global_MAX_EE".
The point is that this error accrue after 10 iterations and sometimes after 2, 3 iterations, it depends. In addition, each time I execute the function without any output argument everything goes well and I finish the 200 iterations. I checked all the functions I have and I am sure all the variables are well assigned and well used. Does any has any clue what to do?
I would be thankful for any suggestions or ideas.
Thank you in advance
採用された回答
その他の回答 (1 件)
Image Analyst
2016 年 2 月 16 日
You declare that it will be an output but nowhere do you ever assign that variable. Find out why.
By the way, it's always a good idea to have the first lines in a function declare your output variables, even if they're null or zero or something. That way you'll avoid the error. In your calling code though you might have to check for valid values. For example, check if the variable is null and if it is then you know you never assigned it a proper values. So, for example, have the first lines in the function be this:
sum_Power = 0; % Whatever number indicates failure
Lambda = 0; % Whatever number indicates failure
exitflag = -1; % Whatever number indicates failure
sum_rate = []; % Null
カテゴリ
ヘルプ センター および File Exchange で Variables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!