Getting error that output argument is not assigned during function when it is?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a function that finds wind speeds between certain lats and lons. This is the first line in my function:
function [d,ccmp]=CCMPLidar2018(latmin,latmax,lonmin,lonmax)
This is my code for when I call the function:
[d,ccmp]=CCMPLidar2018(latmin,latmax,lonmin,lonmax);
It looks exactly alike right? However, I'm getting this error:
[d,ccmp]=CCMPLidar2018(latmin,latmax,lonmin,lonmax);
Output argument "ccmp" (and maybe others) not assigned during call to "CCMPLidar2018".
I just have no idea why I'm getting this error. The function and script are in the same folder, the argument ccmp is included in the function. Does anybody have any idea why I'm getting the error?
2 commentaires
Stephen23
le 24 Nov 2021
Modifié(e) : Stephen23
le 24 Nov 2021
"Does anybody have any idea why I'm getting the error?"
Yes: because the output is not defined inside the function. Just like the error message states.
"Getting error that output argument is not assigned during function when it is?"
Because it isn't.
This depends on the code in your function, not on the function signature (which you showed us).
Usually beginners get this error when they have some IF/ELSEIF/ELSE logic or SWITCH logic or something similar which does not define the output variables on all possible paths. But as you did not show any of the relevant code, we cannot debug this.
If you want more help, you will have to show us your function code.
Réponses (1)
Stephen23
le 24 Nov 2021
Modifié(e) : Stephen23
le 25 Nov 2021
When direc is empty then ccmp is not defined (exactly as the error message states).
This error is easy to demonstrate (showing that the problem is in your code, not the function signature):
[A,B] = test([])
function [x,y] = test(z)
x = 1;
for k = 1:numel(z)
y = 2;
end
end
The solution depends on what you want to do when no files are found: you could throw an error, search for some other files, or define a default value before the loop, e.g.:
ccmp = struct();
for j = ...
end
Note that the code overwrite some of ccmp's fields on each loop iteration.
0 commentaires
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!