MATLAB: Loop-less way to str2double a portion of a cell array in place

loop-free partial cellarray conversionMATLAB

Hi! I feel like I shouldn't need to ask this by now, but everyway I try doesn't work: I have a cellstr array, some elements of which are character representations of numbers, e.g., A = {'0', 'hello', '2'}; I want to convert this to A = {0, 'hello', 2}. I've tried dozens of variations of: A(~isnan(str2double(A))) = str2double(A(~isnan(str2double(A)))) (I actually have a separate indexing arry, I'm just using isnan for illustrative purposes, but it does extract the sub-array I want to convert) involving {} instead of () in various places, cellfun, arrayfun, deal, mat2cell, cell2mat, etc., and everything either returns an error or assigns the whole target sub-array to every target array element, i.e., I get A = {{0,2}, 'hello', {0,2}}. Is there a loop-less way to convert {'0', 'hello', '2'} to {0, 'hello', 2}? Thanks!
DG

Best Answer

isnan(cellfun(@str2double,your_cell));