MATLAB: Recursion for Unnesting 1×1 Cell Array

recursion

I have been getting continuous errors for reaching the maximum recursion limit when running various test cases for my function. Since unnesting a 1×1 cell array to get a string can usually be done by:
ca = {{{'math'}}}
while iscell(ca)
ca = ca{1}
end
out = ca
For recursion, I did this:
function out = doYouEverFeel(ca)
if ischar(ca)
out = ca
else
out = doYouEverFeel(ca{1});
end
end
Why is this not working?

Best Answer

Are you sure it is a single quote char string 'example' and not a double quote string "another_example"? What is the actual error message displayed? Your recursion code will only work if the end result is always a char variable.