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 Comment

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.

Sign in to comment.

Answers (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));

Categories

Tags

Asked:

on 9 Jul 2013

Community Treasure Hunt

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

Start Hunting!