MATLAB: Function output name unused

output name

I specified a function whose output is named 'finalOutputs', every time I run the function, it populates an output without the name but 'ans'. When I debug it line by line, it works well and returns the output in 'finalOutputs' matrix, but once I exit debugger, another matrix 'ans' appeared. Why does this happened? I'm new to Matlab and really confused about it.
function [finalOutputs] = func(input1, input2,...)

Best Answer

When you execute the function, the local variable finalOutputs will get assigned to. However, that does not affect any variables in the workspace of the caller of the function. The calling function needs to deliberately assign the output to some variable (which might have a completely different name.)
MATLAB function inputs and outputs are handled positionally not by name.