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

답변 (3개)

Jan
Jan 2013년 10월 6일
편집: Jan 2013년 10월 6일

0 개 추천

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 2013년 10월 6일

0 개 추천

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

댓글 수: 1

Jan
Jan 2013년 10월 6일
This fails when any element of the input is outside [0, 9].

댓글을 달려면 로그인하십시오.

Andrei Bobrov
Andrei Bobrov 2013년 10월 6일
편집: Andrei Bobrov 2013년 10월 7일

0 개 추천

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

댓글 수: 2

Jan
Jan 2013년 10월 6일
편집: Jan 2013년 10월 6일
This fails when any element of the input is outside [0, 9].
Andrei Bobrov
Andrei Bobrov 2013년 10월 7일
편집: Andrei Bobrov 2013년 10월 7일
Hi Jan, I agree with you and I suggest another option.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

질문:

2013년 10월 6일

편집:

2013년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by