Convert a matrix to { }
1 回表示 (過去 30 日間)
古いコメントを表示
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'}.
0 件のコメント
回答 (3 件)
Jan
2013 年 10 月 6 日
編集済み: Jan
2013 年 10 月 6 日
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.
0 件のコメント
Andrei Bobrov
2013 年 10 月 6 日
編集済み: Andrei Bobrov
2013 年 10 月 7 日
A = [0 1 2
3 4 5
6 7 8];
cellstr(sprintf('%d',A')')'
other variant:
regexp(num2str(reshape(A.',1,[])),'\d*','match')
2 件のコメント
Andrei Bobrov
2013 年 10 月 7 日
編集済み: Andrei Bobrov
2013 年 10 月 7 日
Hi Jan, I agree with you and I suggest another option.
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!