I have the following cell array:
>> tmp0 = {'foo', '%s', 'one'; 'bar', '%d', 3}
tmp0 =
2×3 cell array
'foo' '%s' 'one'
'bar' '%d' [ 3]
I can use it like this with sprintf
:
>> sprintf('%s,%d', tmp0{:,3})
ans =
'one,3'
I would like to be able to achieve the same thing with a function call, since if I have a function that generates a cell array, say genCell()
, I don't think I can achieve something like genCell(){:}
in MATLAB.
So I made this function:
function cellExp(cellIn)
cellIn{:}
end
Although dubious it seems to work as expected so far, since calling cellExp(tmp0(:,3))
seems to be the same as calling tmp0{:,3}
>> cellExp(tmp0(:,3))
ans =
'one'
ans =
3
>> tmp0{:,3}
ans =
'one'
ans =
3
However, ultimately, I cannot use it as desired:
>> sprintf('%s,%d', cellExp(tmp(:,3)))
Error using cellExp
Too many output arguments.