How to split strings lines to Matrix columns?
2 次查看(过去 30 天)
显示 更早的评论
I have .csv files in which the data comes in 12-bit format on each string line. Each bit is the state of a different event, and I would like to split each string line into 12 different matrix columns, so I can easily browse the states by matrix index.
Example:
Split
100010001000 100000000000
into
M=[1 0 0 0 1 0 0 0 1 0 0 0; 1 0 0 0 0 0 0 0 0 0 0 0]
I am using textscan to read the .csv into a cell array, but cannot manage to split it into different columns, since I do not have a defined delimiter. Any advice on this basic question would be greatly appreciated.
0 个评论
采纳的回答
Azzi Abdelmalek
2016-6-6
编辑:Azzi Abdelmalek
2016-6-6
A={'100010001000'
'100000000000'}
M=cell2mat(cellfun(@(x) x-'0',A,'un',0))
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!