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?

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)

 채택된 답변

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

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');
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.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2013년 7월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by