Reverse characters of each element in a cell array (Matlab)

333 views Asked by At

I have a cell array as follows:

    celldata = {'AB'; 'BE'; 'BC'}

How can I create a cell array which characters of each element in a cell array 'celldata' are reversed. The output should be as follows:

    recelldata = {'BA'; 'EB'; 'CB'}

Thanks!

1

There are 1 answers

1
GameOfThrows On BEST ANSWER

you could use fliplr, but it operates on each index of the cell instead of the whole cell. To wrap it all in one line, use cellfun

recelldata = cellfun(@(x) fliplr(x), celldata,'UniformOutput', false)

>>'BA'
  'EB'
  'CB'