how can remove words and split in cellarray in matlab

조회 수: 1 (최근 30일)
Ava persiangulf
Ava persiangulf 2018년 6월 10일
편집: Stephen23 2018년 6월 10일
for example x={'100614,Peter Beadle,131542'}; i want x= [100614,131542] my dataset have 408934 record like 'x'

채택된 답변

Paolo
Paolo 2018년 6월 10일
편집: Paolo 2018년 6월 10일
For input:
x = {'100614,Peter Beadle,131542'}
You can use regexp to match numerical entries in your cell. The expression below matches numbers from 0-9 for 6 times since the numbers in your cell have exactly 6 digits.
x={'100614,Peter Beadle,131542'};
[tokens,matches] = regexp(x,'[0-9]{6}','match');
x = str2double(tokens{:});
For input:
x = {'100614','Peter Beadle','131542'}
Use the following:
x = {'100614','Peter Beadle','131542'};
x = str2double(x);
x(isnan(x)) = [];
  댓글 수: 10
Ava persiangulf
Ava persiangulf 2018년 6월 10일
편집: Stephen23 2018년 6월 10일
that's answered for me but make change data in my dataset, for example, x=[8213430049,100573,100614] change to x=[8.213430049100573] .... but your answer was very helpful and thank you very much
Paolo
Paolo 2018년 6월 10일
You are welcome. In that case, try using:
x = [8213430049,100573,100614];
x = num2str(x);
x = strsplit(x,' ');
x = str2double(strcat(x{1}(1),'.',x{1}(2:end),x{2}));
x = 8.213430049100573

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by