필터 지우기
필터 지우기

read part of string

조회 수: 1 (최근 30일)
MIHYUN
MIHYUN 2014년 7월 12일
댓글: Image Analyst 2014년 7월 12일
I have mat file like 'name.mat'
name(1,1) = Italy
name(2,1) = Rome, Italy
And I want to get 'Rome'.
I do not know the function that I want.
Please help me.

채택된 답변

Star Strider
Star Strider 2014년 7월 12일
This will work, but no guarantee that it will easily generalise to more complicated situations:
name(1,1) = {'Italy'};
name(2,1) = {'Rome, Italy'};
x = findstr(name{2},',');
y = name{2}(1:x-1)
produces:
y =
Rome
This is only one way (and probably the simplest). There are many others.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 7월 12일
name = {'Italy'; 'Rome, Italy'} % Cell array. Use braces not parentheses.
words = allwords(name{2,1}) % words = 'Rome' 'Italy'
Or simply use normal indexing as usual to extract the first 4 characters of the contents of the second cell:
rome = name{2,1}(1:4)

카테고리

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