Getting error that output argument is not assigned during function when it is?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2021-11-24
编辑:Stephen23
2021-11-24
"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.
回答(1 个)
Stephen23
2021-11-24
编辑:Stephen23
2021-11-25
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!