Split column data into two columns

조회 수: 2 (최근 30일)
Kellie Anton
Kellie Anton 2017년 8월 2일
댓글: Honglei Chen 2017년 8월 3일
I have a column of data with numbers formatted as a string. All of the 3,000 plus entries are five characters long such as 01234. I would like to split that out into two columns so that one column would be the first two numbers and the other the last three, such as 01 234. I cannot seem to find the right solution for this. Any thoughts?
  댓글 수: 1
Kellie Anton
Kellie Anton 2017년 8월 3일
편집: Kellie Anton 2017년 8월 3일
I finally got something to work. I had to take my column out into its own cell array 'goop'.
glop = cellfun(@(x) x(1:2), goop, 'UniformOutput', false);
glup = cellfun(@(x) x(3:end), goop, 'UniformOutput', false);
Honestly, I do not understand why it would not let me do it in the table directly. Instead, it just gives me a column of 2X1 cells.
Anyhow, this will work for my purposes. I just was hoping for something more... efficient.

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

답변 (1개)

Honglei Chen
Honglei Chen 2017년 8월 2일
Could you elaborate what you have as a matrix?
If you are using character arrays, it should just be a 5-column matrix to start with. So all you need to do is just getting the first 2 columns and then last 3 columns. For example
a = ['01234';'12345']
a(:,1:2)
a(:,3:5)
Does this help?
  댓글 수: 3
Kellie Anton
Kellie Anton 2017년 8월 3일
Here is what I tried this morning...
glop = goop(:,1:2);
Index exceeds matrix dimensions.
goop is a 3283X1 cell.
Honglei Chen
Honglei Chen 2017년 8월 3일
maybe you can try
glop = goop{1}(:,1:2)
HTH

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by