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 次查看(过去 30 天)
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)

采纳的回答

Andrei Bobrov
Andrei Bobrov 2013-7-10
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{:});

更多回答(2 个)

Jan
Jan 2013-7-10
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 2013-7-10
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.

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by