cell consisting letters and numbers to matrix double

2 Ansichten (letzte 30 Tage)
Lotte van de Venis
Lotte van de Venis am 27 Okt. 2017
Kommentiert: Cedric am 29 Okt. 2017
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.
Thanks in advance!
  2 Kommentare
Jan
Jan am 27 Okt. 2017
Please give any meaningful example. What is the wanted result for 'ABC123'? How do you want to convert this to a number?
Walter Roberson
Walter Roberson am 28 Okt. 2017
xlswrite('Name Excelfile.xlsx', [num2cell(Group), num2cell(Trail), mTrail], 1)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cedric
Cedric am 27 Okt. 2017
Bearbeitet: Cedric am 27 Okt. 2017
>> 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'}
{'CAD'}
{'ZED'}
>> data{2}
ans =
8.0000
90.8700
40.0000
  4 Kommentare
Cedric
Cedric am 27 Okt. 2017
Please see my updated answer.
Cedric
Cedric am 29 Okt. 2017
Does it solve your problem of splitting alpha codes and numbers or do you still have a problem with that?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by