Splitting up data in a single cell to a multiple columns array

조회 수: 46 (최근 30일)
Ori Ossmy
Ori Ossmy 2023년 1월 30일
댓글: Ori Ossmy 2023년 1월 30일
Hi,
I have a table of data that is 3275x1. In each cell, there is a large amount of data in groups of threes, each seperated by semi-colons. The pattern of the data in each cell is 'X-coordinate, Y-coordinate, T-value; X-coordinate(2), Y-coordinate(2), T-value(2);' (and so on, many times). For instance, part of the data of a single cell looks like the following (Importantly, each cell starts and ends with an apostraphe ('):
'530,510,165713557972;530,511,16523281757976;631,512,1657123213423478;...etc.
So here, 530 is the first X-coordinate, 510 is the first Y-coordinate, and 1657[...] is the first T-value. Then after the semi-colon, comes the second X, Y and T values. This pattern is repeated many more times in each cell.
I'm currently trying to split up the data into three different arrays - one with X-values, one with Y-values, and one with T-values. I imagine you'd need some sort of for loop to split the data up like this, but I'm afraid I'm struggling to figure out how to do this.
I hope the question makes sense, and any help would be greatly appreciated!
Thanks a lot.
  댓글 수: 4
Stephen23
Stephen23 2023년 1월 30일
@Ori Ossmy: what would help is if you uploaded your original data file by clicking the paperclip button.
Most likely this mess can be fixed by some improvements to the file importing.
Ori Ossmy
Ori Ossmy 2023년 1월 30일
I've found a good way to sort the data as per Aritra's answer, but thanks so much for the helpful response.

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

채택된 답변

Aritra
Aritra 2023년 1월 30일
Hi,
As per my understanding you are trying to split up the data of a single cell to a multiple columns array. Since the data is in string format it needs certain preprocessing.
To do so you can make use of the split function followed by the reshape function. The split(str,delimiter) function helps to split a string at delimiters. The reshape(A,sz) function helps to reshape an array to a desired size.
In the below example suppose the example variable needs to be divided into 2x3 matrix. To do so you can use the following code snippet:
example = '530,510,165713557972;530,511,16523281757976';
t = split(example ,{',',';'});
t = reshape(t,[3,2])';
Refer the following pages for more information on split and reshape:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by