MATLAB: Error in storing the output of sprintf in a cell array

cell arrayMATLAB

Why I am getting error
Cell contents assignment to a non-cell array object.
while storing printf output in a cell array?
name='my_text'
a{1}=sprintf('%s',name)
I find the another solution to resolve this.
name='my_text'
a=sprintf('%s',name)
N{1}=a
Why I am getting the error in the first case?

Best Answer

>> a{1}=sprintf('%s',name)
Cell contents assignment to a non-cell array object.
because a is assigned a string constant before this code. Do
clear a
and it will work
>> clear a
>> a{1}=sprintf('%s',name)
a =
'my_text'
One cannot change the class of a variable when indexing. However, this works
>> a='abc'; a = {sprintf('%s',name)}
a =
'my_text'