MATLAB: Kindly explain this command

cellfun

final_song = cellfun(@plus, alto, treb, 'Uniform', 0);
Kindly explain this command. Basically i want to add alto and treb and they are being added. what does uniform and 0 mean in this command

Best Answer

Option Uniform or UniformOutput set to 0 (or false) means, that output from function will be stored in cell array. It is necessary when function (in your case plus) returns non scalar values. If you set the UniformOutput value to 1 ( or true), your function must return scalar values and the output will be concatenated into an array.
Look at examples:
a = {rand(1),rand(2),rand(3),rand(4)}
b = {rand(1),rand(2),rand(3),rand(4)}
cellfun(@plus,a,b,'UniformOutput', false)
a = {rand(1),rand(1),rand(1),rand(1)}
b = {rand(1),rand(1),rand(1),rand(1)}
cellfun(@plus,a,b,'UniformOutput', false)
a = {rand(1),rand(1),rand(1),rand(1)}
b = {rand(1),rand(1),rand(1),rand(1)}
cellfun(@plus,a,b,'UniformOutput', true)