I have a cellArray data. Could you tell me how I can extract the first column of this cellArray data without depending any character and number?

1 view (last 30 days)
cellArray =
'A29G0202 465254.432 4066809.025'
'A29G0008 499252.083 4042876.84'
'A29G0014 494404.625 4047958.526'
Name Size Bytes Class Attributes
cellArray 22x1 ... cell
%I want to extract first column of cellArray. (A29G0202, A29G0008, A29G0014)

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 10 Jul 2013
cellArray ={'A29G0202 465254.432 4066809.025';
'A29G0008 499252.083 4042876.84';
'A29G0014 494404.625 4047958.526'};
a = regexp(cellArray,'^([a-zA-Z]*\d*)*','match');
out = cat(1,a{:});

More Answers (2)

Jan
Jan on 10 Jul 2013
No, the cell array you show us has one column only, as you can see by the size {22 x 1}. The elements of the cells contain the complete rows as a string and this is obviously a bad idea. So I suggest to improve the method you have used to create this cell array, such that you get something like this directly:
cellArray = { ...
'A29G0202', '465254.432', '4066809.025'; ...
'A29G0008', '499252.083', '4042876.84'; ...
...
}
Then the extraction is trivial:
cellArray(:, 1)
Perhaps something like this helps to create the cell array:
textscan(fid, '%s %s %s');

dpb
dpb on 10 Jul 2013
MATL
>> t=textscan(char(cellArray),'%s %*[^\n]');
>> reshape(char(t{:}),length(cellArray,[])
ans =
A29G0202
A29G0008
A29G0014
>>
Be easier if you would use
'CollectOutput', true
when you read the data to begin with.

Categories

Find more on Data Type Identification in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!