How to split strings lines to Matrix columns?

6 views (last 30 days)
I M on 6 Jun 2016
Commented: I M on 8 Jun 2016
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.
100010001000 100000000000
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.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 6 Jun 2016
Edited: Azzi Abdelmalek on 6 Jun 2016
M=cell2mat(cellfun(@(x) x-'0',A,'un',0))
  1 Comment
I M on 8 Jun 2016
Thanks! It worked exactly the way I was envisioning. Thank you also for the very prompt response.

Sign in to comment.

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 6 Jun 2016
k=['100010001000'; '100000000000'];
out = k -'0'


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!