replace in a cell array every " with a # in matlab

Here is a sample code that replaces every " with a # in a cell array in MATLAB:

main.m
% define a sample cell array
inputArray = {'a"b"c', 'd"e"f', 'g"h"i'};

% iterate through each cell in the array
for i = 1:numel(inputArray)

    % get the current cell as a string
    currentString = inputArray{i};

    % replace all " with #
    currentString = strrep(currentString, '"', '#');

    % write the updated string back to the cell array
    inputArray{i} = currentString;
end

% display the modified cell array
disp(inputArray);
444 chars
19 lines

The output of this code will be:

main.m
{
  [1,1] = a#b#c
  [1,2] = d#e#f
  [1,3] = g#h#i
}
52 chars
6 lines

related categories

gistlibby LogSnag