I have a function with the following prototype
function [bandwidth,density,X,Y,x,y]=kde2d(data,n,MIN_XY,MAX_XY)
basically the function returns 6 outputs as above, some are in vector form while others are a numerical quantity. How can I elegantly pass the output from the function into a 1 by 6 cell array?
how about
[a{1:6}] = kde2d( data, n, MIN_XY, MAX_XY )
Edit:
consider this annoying function
def foo(n):
if n == 1:
return [1, ]
elif n == 2:
return [1, ], {'a': 2}
elif n == 3:
return [1, ], {'a': 2}, (3, 3, 3)
return [1, ], {'a': 2}, (3, 3, 3), None
You can always get all the outputs into a single tuple:
for i in range(1, 5):
f = foo(i)
print('got {} outputs: {}'.format(len(f), f))
and the output of this simple loop would be:
got 1 outputs: [1] got 2 outputs: ([1], {'a': 2}) got 3 outputs: ([1], {'a': 2}, (3, 3, 3)) got 4 outputs: ([1], {'a': 2}, (3, 3, 3), None)
If you want to get a specific output:
f = foo(2)
f[1] # accessing the second output, {'a': 2} in this example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With