Merge elements of a row into a single element array
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JohnDylon
el 11 de Sept. de 2016
Comentada: JohnDylon
el 11 de Sept. de 2016
Hi,
I want to merge each row of CHAR type matrix
BB=[C I M G 2 8 3 0; C I M G 2 8 3 2; C I M G 2 8 3 3; C I M G 2 8 3 4]
as
BBB=[CIMG2830; CIMG2832; CIMG2833; CIMG2834]
or in other words I want to merge each row into one single element, not necessarily all elements are numbers.
Any ideas?
0 comentarios
Respuesta aceptada
Walter Roberson
el 11 de Sept. de 2016
BB=['C' 'I' 'M' 'G' '2' '8' '3' '0'; 'C' 'I' 'M' 'G' '2' '8' '3' '2'; 'C' 'I' 'M' 'G' '2' '8' '3' '3'; 'C' 'I' 'M' 'G' '2' '8' '3' '4']
is already completely equivalent to
BBB = ['CIMG2830'; 'CIMG2832'; 'CIMG2833'; 'CIMG2834']
Are you sure you are starting with a char matrix? And not, perhaps, a cell array whose elements are each single char ? If what you have is
BB={'C' 'I' 'M' 'G' '2' '8' '3' '0'; 'C' 'I' 'M' 'G' '2' '8' '3' '2'; 'C' 'I' 'M' 'G' '2' '8' '3' '3'; 'C' 'I' 'M' 'G' '2' '8' '3' '4'}
then
BBB = reshape( horzcat(BB{:}), size(BB,1), [])
3 comentarios
Walter Roberson
el 11 de Sept. de 2016
Editada: Walter Roberson
el 11 de Sept. de 2016
Do not use cell2mat() for that purpose. Instead, use
char(aa)
as that will convert the cell array of strings into a row-based array of char.
However, you would seldom need that. You would typically instead use something like,
filename = aa{k};
fullname = fullfile(folder, filename);
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!