필터 지우기
필터 지우기

How to create variables from table cell array containing char array into separate column

조회 수: 2 (최근 30일)
i have table with border coordinates loaded from spreadsheet.
Example data:
testdata = {'POLYGON ((72502 146871.5, 72566 146839.5, 72614 146791.5))';'POLYGON ((64462 138105.5, 65422 139241.5, 65694 139289.5))'};
T = table(testdata);
i want to create two columns variable of x and y from the table say for the first row of T.testdata(1) the output should become:
x = [72502;72566;72614] and y=[146871.5;146839.5;146791.5]
how can i achieve this? with regexp i manage to strip the unnecessary data
test_regex = regexp(T.testdata{1,1},'[^\(\)]+(?=\))','match');
test_regex{1,1}
ans =
'72502 146871.5, 72566 146839.5, 72614 146791.5'

답변 (1개)

fareed jamaluddin
fareed jamaluddin 2018년 6월 20일
I have managed to further solve this by the following step:
newChr = strrep(test_regex{1,1},',',';');
testit = str2num(newChr);
x = testit(:,1)
y = testit(:,2)
but i believe there is more optimised way to do this?

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by