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'}.

Antworten (3)

Jan
Jan am 6 Okt. 2013
Bearbeitet: Jan am 6 Okt. 2013

0 Stimmen

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.
Jan
Jan am 6 Okt. 2013

0 Stimmen

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

1 Kommentar

Jan
Jan am 6 Okt. 2013
This fails when any element of the input is outside [0, 9].

Melden Sie sich an, um zu kommentieren.

Andrei Bobrov
Andrei Bobrov am 6 Okt. 2013
Bearbeitet: Andrei Bobrov am 7 Okt. 2013

0 Stimmen

A = [0 1 2
3 4 5
6 7 8];
cellstr(sprintf('%d',A')')'
other variant:
regexp(num2str(reshape(A.',1,[])),'\d*','match')

2 Kommentare

Jan
Jan am 6 Okt. 2013
Bearbeitet: Jan am 6 Okt. 2013
This fails when any element of the input is outside [0, 9].
Andrei Bobrov
Andrei Bobrov am 7 Okt. 2013
Bearbeitet: Andrei Bobrov am 7 Okt. 2013
Hi Jan, I agree with you and I suggest another option.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 6 Okt. 2013

Bearbeitet:

am 7 Okt. 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by