MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Martin Park
on 6 Oct 2013

Can anyone help me to convert a matrix that is for instance:

0 1 2 3 4 5 6 7 8

called symbols obtained from an image to something that is in the following form symbols= {'0' '1' '2' '3' '4' '5' '6' '7' '8'}.

*No products are associated with this question.*

Answer by Jan Simon
on 6 Oct 2013

Edited by Jan Simon
on 6 Oct 2013

symbols = [0 1 2; ... 3 4 5; ... 6 7 8]; S = sprintf('%g*', symbols.'); S(end) = []; % Remove trailing * C = regexp(S, '*', 'split');

Another simpler method:

C = cell(1, numel(symbols)); symbols = symbols.'; for iC = 1:numel(symbols) C{iC} = sprintf('%g', symbols(iC)); end

I'm not convinced, that the conversion will really help to solve your problem.

Answer by Jan Simon
on 6 Oct 2013

Or:

symbols = [0 1 2; 3 4 5; 6 7 8]; C = num2cell(char('0' + symbols.'))

Answer by Andrei Bobrov
on 6 Oct 2013

Edited by Andrei Bobrov
on 7 Oct 2013

A = [0 1 2 3 4 5 6 7 8];

cellstr(sprintf('%d',A')')'

other variant:

regexp(num2str(reshape(A.',1,[])),'\d*','match')

## 0 Comments