Splitting up data in a single cell to a multiple columns array
古いコメントを表示
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 件のコメント
"Importantly, each cell starts and ends with an apostraphe (')"
Did you actually check if the data really start & end with apostrophes (if so, how?), or are you just confusing how data are displayed with what data are stored in memory?
"I imagine you'd need some sort of for loop to split the data up like this"
I don't see why:
str = '530,510,165713557972;530,511,16523281757976;631,512,1657123213423478;...';
tkn = regexp(str,'(\d+),(\d+),(\d+);','tokens');
tkn = vertcat(tkn{:})
format long G
mat = str2double(tkn)
Ori Ossmy
2023 年 1 月 30 日
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
2023 年 1 月 30 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!