You don't have a choice when dealing with regular expressions. You must convert the numbers to strings if you want to use numbers for regular expressions. However, Luis Mendo's approach is more simpler as you just need another if statement in your logic branches. That method is fine too, and more simpler.
If you don't want to do this and want to use numbers in regular expressions, we can keep track of which elements in your cell array were numbers to begin with, convert those numbers to strings, use regexprep, then convert these entries back to numbers when you're done.
You can use cellfun to check which elements in your cell array are numbers. Then, convert these elements to strings, do your processing, then convert back. First check to see if each element is a number by isnumeric. After this, you can use num2str to convert the numbers into strings. After, use str2num to convert the strings back to numbers. In other words, do this:
myCell1 = {'';'"some words"';64;23;'"words"'};
myCell2={'';'more words';'more stuff';46;15};
Cell={myCell1, myCell2};
newCellArray = cell(1,numel(Cell)); %// Place output cell array here
for i = 1 : numel(Cell)
%// Extract i'th cell
cel = Cell{i};
%// Which ones are numbers?
whichAreNumbers = cellfun(@isnumeric, cel);
%// Convert those numbers into strings
outStrings = cellfun(@num2str, cel(whichAreNumbers), 'uni', false);
%// Assign back into cell
cel(whichAreNumbers) = outStrings;
%// Apply regexprep now
newCell = regexprep(cel, '^"|"$', '');
%// Convert the numbers back
outVals = cellfun(@str2num, newCell(whichAreNumbers), 'uni', false);
newCell(whichAreNumbers) = outVals;
%// Place in master output cell array
newCellArray{i} = newCell;
end
The output at this point is:
>> celldisp(newCellArray)
newCellArray{1}{1} =
''
newCellArray{1}{2} =
some words
newCellArray{1}{3} =
64
newCellArray{1}{4} =
23
newCellArray{1}{5} =
words
newCellArray{2}{1} =
''
newCellArray{2}{2} =
more words
newCellArray{2}{3} =
more stuff
newCellArray{2}{4} =
46
newCellArray{2}{5} =
15
As you can see, the numbers are still preserved but the quotes for each of the strings are removed.