Combining elements in an array
显示 更早的评论
Hi, I have a logical array, A = [1 0 1]. How can I combine the elements horizontally, so that I have B = [101]? Any help would be appreciated! SS
采纳的回答
更多回答(1 个)
James Tursa
2016-7-12
编辑:James Tursa
2016-7-12
Assuming you intend to combine the individual digits into a single decimal number:
B = sum(A.*(10.^(numel(A)-1:-1:0)));
If you intended to make a string instead, then
B = char(A+'0');
类别
在 帮助中心 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!