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

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개)

a = regexp(cellstr(a),'\d*(\.\d*)?','match');
b = str2double(cat(1,a{:}));
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에 대해 자세히 알아보기

태그

질문:

2013년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by