Convert a matrix to { }
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
Jan
el 6 de Oct. de 2013
Editada: Jan
el 6 de Oct. de 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.
0 comentarios
Jan
el 6 de Oct. de 2013
Or:
symbols = [0 1 2; 3 4 5; 6 7 8];
C = num2cell(char('0' + symbols.'))
1 comentario
Andrei Bobrov
el 6 de Oct. de 2013
Editada: Andrei Bobrov
el 7 de Oct. de 2013
A = [0 1 2
3 4 5
6 7 8];
cellstr(sprintf('%d',A')')'
other variant:
regexp(num2str(reshape(A.',1,[])),'\d*','match')
2 comentarios
Andrei Bobrov
el 7 de Oct. de 2013
Editada: Andrei Bobrov
el 7 de Oct. de 2013
Hi Jan, I agree with you and I suggest another option.
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!