Merging row elements into single numbers
6 次查看(过去 30 天)
显示 更早的评论
If you have the 3*3 matrix
C = [3 4 5
6 7 9
1 5 8]
and you want to change it to the 3*1 matrix
C = [345
679
158]
so that you can for example sort it in descending order of the rows, how would you do this? Thank you.
0 个评论
采纳的回答
Chris
2021-10-31
编辑:Chris
2021-10-31
Edit: Use Star Strider's answer. It's faster.
C = [3 4 5
6 7 9
1 5 8]
C = double(string(C).join(''))
3 个评论
Star Strider
2021-10-31
Another approach —
C = [3 4 5
6 7 9
1 5 8]
C*10.^[2;1;0]
Just thought I’d add that for fun!
.
Chris
2021-10-31
Interesting. This was probably the most obvious method before strings? Easily generalized for an array of single-digit integers:
C*10.^[size(C,2)-1:-1:0]'
更多回答(0 个)
另请参阅
类别
在 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!