how can remove words and split in cellarray in matlab
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
for example x={'100614,Peter Beadle,131542'}; i want x= [100614,131542] my dataset have 408934 record like 'x'
채택된 답변
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
>> x = str2double(tokens{:});
- Error using str2doubleToo many input arguments.
- not answered.....why?
Is your x definitely
x={'100614,Peter Beadle,131542'}
and not
x={'100614','Peter Beadle','131542'}
?
str2double only accepts one input argument, so this
str2double(tokens{:})
will not work if tokens contains multiple cells. str2double's one input argument may be cell array, so perhaps you meant to use that:
tokens = vertcat(tokens{:});
str2double(tokens)
str2double(tokens{:})
returns the correct array.
str2double(tokens)
returns NaN.
At least on my machine with 2017b. I suspect that her input is not a single cell but rather a cell array.
yes, tokens contain multiple cells
If your input x is:
x={'100614','Peter Beadle','131542'}
Then use:
x = {'100614','Peter Beadle','131542'};
x = str2double(x);
x(isnan(x)) = [];
If you confirm that's the format of your input, I'll edit my answer.
thanks for answering,.... What should I do now?
@Ava,
I have modified my answer. It now contains a solution for both inputs. If the problem is solved you can accept my answer. Consider perhaps adding the other input to your question.
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
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개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
