MATLAB: How to pass cell array as input to function

the function is not taking value inside {1x1 cell} i am new in matlab please help me.

I have a cell array which contains 10 {1×1 cell} cells now I want to pass this cell array as input to a function and access the element inside the {1×1 cell} how should I pass the cell array?

Best Answer

" I want to pass this cell array as input to a function and access the element inside"
There are (at least) three interpretations of that.
Pass each element in as a single input
C = arrayfun(@(x){x},1:10); % demo data


z = myFun(C{:});
function z = myFun(a,b,c,d,e,f,g,h,j,k)
z = a+b+c+d+e+f+g+h+j+k;
end
Condense the inputs into a vector and pass as 1 input
C = arrayfun(@(x){x},1:10); % demo data
y = myFun2([C{:}]);
function z = myFun2(n)
z = sum(n);
end
Pass the entire cell array
C = {1,2}; % demo data
y = myFun2(C);
function z = myFun2(n)
z = C{1} + c{2};
% or
% z = sum([C{:}]);
end