replace every " with an one ' in an cell array in matlab in matlab

You can use cellfun with strrep function to replace every double quote mark with a single quote mark in a cell array in MATLAB. Here's an example:

main.m
% Sample cell array
myCellArray = {'Hello "world"', 'This is "a test".'};

% Replace double quotes with single quotes
myCellArray = cellfun(@(x) strrep(x, '"', ''''), myCellArray, 'UniformOutput', false);

% View modified cell array
disp(myCellArray);
252 chars
9 lines

Output:

main.m
    'Hello ''world'''
    'This is ''a test''.'
48 chars
3 lines

Here, we first create a sample cell array myCellArray containing two strings, each containing double quotes. We then use the cellfun function to apply the strrep function on each element of myCellArray. The strrep function replaces every occurrence of the double quote mark (") with the single quote mark ('). Finally, we set the 'UniformOutput' option of cellfun to false to indicate that the output should be a cell array (rather than a matrix).

related categories

gistlibby LogSnag