Merge elements of a row into a single element array
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2016-9-11
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 个评论
Walter Roberson
2016-9-11
编辑:Walter Roberson
2016-9-11
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!