# cell consisting letters and numbers to matrix double

9 ビュー (過去 30 日間)
Lotte van de Venis 2017 年 10 月 27 日
コメント済み: Cedric Wannaz 2017 年 10 月 29 日
Hi,
I have a matrix containing 840x1 cells. These consist of 3 letters followed by numbers. Is there a way to convert this into 840x1 double?
I have tried str2double, but these returns only NaN. I tried several combinations with num2str, char, celstr, but i can't figure it out.

#### 2 件のコメント

Jan 2017 年 10 月 27 日
Please give any meaningful example. What is the wanted result for 'ABC123'? How do you want to convert this to a number?
Walter Roberson 2017 年 10 月 28 日
xlswrite('Name Excelfile.xlsx', [num2cell(Group), num2cell(Trail), mTrail], 1)

サインインしてコメントする。

### 回答 (1 件)

Cedric Wannaz 2017 年 10 月 27 日

>> C = {'ABC8', 'CAD90.87', 'ZED40'} ;
>> C2 = cellfun( @(s)s(4:end), C, 'UniformOutput', false ) ;
>> str2double( C2 )
ans =
8.0000 90.8700 40.0000
EDIT 1: here is a solution that extracts both parts:
>> data = textscan( [C{:}], '%3s%f' ) ;
With that you get
>> data
data =
1×2 cell array
{3×1 cell} {3×1 double}
>> data{1}
ans =
3×1 cell array
{'ABC'}
{'ZED'}
>> data{2}
ans =
8.0000
90.8700
40.0000

#### 4 件のコメント

Walter Roberson 2017 年 10 月 27 日
How do you want the 'ABC' to be encoded into the double that you need to be output?
Cedric Wannaz 2017 年 10 月 27 日