How to split strings lines to Matrix columns?

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.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 6월 6일
편집: Azzi Abdelmalek 2016년 6월 6일

0 개 추천

A={'100010001000'
'100000000000'}
M=cell2mat(cellfun(@(x) x-'0',A,'un',0))

댓글 수: 1

I M
I M 2016년 6월 8일
Thanks! It worked exactly the way I was envisioning. Thank you also for the very prompt response.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 6월 6일

0 개 추천

k=['100010001000'; '100000000000'];
out = k -'0'

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

I M
2016년 6월 6일

댓글:

I M
2016년 6월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by