go through an cell array and swap "" with '' in matlab

You can use a for loop to iterate over each element of the cell array and replace every occurrence of "" with '' using the strrep function. Here's an example code snippet:

main.m
% Example cell array
cellArray = {'', 'a', 'b'; 'c', '', 'd'; 'e', 'f', ''};

% Iterate over each element of the cell array
for i = 1:size(cellArray, 1)
    for j = 1:size(cellArray, 2)
        % Replace every occurrence of "" with ''
        cellArray{i, j} = strrep(cellArray{i, j}, '""', "''");
    end
end
310 chars
11 lines

This code snippet uses two nested for loops to iterate over every element of the cell array. It then uses the strrep function to replace every occurrence of "" with '' in each element. The result is a modified cell array where all empty strings are represented by single quotes instead of double quotes.

related categories

gistlibby LogSnag