I have a data which class is char, containing n rows and 4 columns. I wanna extract first column.
이전 댓글 표시
a=
N334 4261461.0645 2661117.6797 3918916.0472
N352 4266205.852 2659683.96 3914798.2885
N404 4258400.8221 2662966.354 3920634.872
%class=char
%I wanna extract first column, (N334 N352 N404) from this char data.
%also every rows and columns would include numbers.
b=
334 4261461.0645 2661117.6797 3918916.0472
352 4266205.852 2659683.96 3914798.2885
404 4258400.8221 2662966.354 3920634.872
class=char %in this case solution is same to above data or different codes available?
댓글 수: 1
Jan
2013년 7월 9일
No, the shown variable "a" does not have the type char and 4 columns. It looks more like a cell string. Please post the code, which creates the data you have. Otherwise important details of the question must be guessed. Please note that "class=char" is cryptic.
답변 (2개)
Andrei Bobrov
2013년 7월 9일
편집: Andrei Bobrov
2013년 7월 9일
a = regexp(cellstr(a),'\d*(\.\d*)?','match');
b = str2double(cat(1,a{:}));
Jan
2013년 7월 9일
With some bold guessing:
a = {'N334' '4261461.0645' '2661117.6797' '3918916.0472'; ...
'N352' '4266205.852' '2659683.96' '3914798.2885'; ...
'N404' '4258400.8221' '2662966.354' '3920634.872'}
a = strrep(a, 'N', '');
s = sprintf('%s*', a{:});
d = reshape(sscanf('%g*'), size(a));
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!