Finding a series of numbers in a cell

1 Ansicht (letzte 30 Tage)
Patrick
Patrick am 15 Aug. 2017
Kommentiert: Patrick am 15 Aug. 2017
Good day,
I have the following cell called "c"
c = {'Conc_510_Y2_Asym_27730_AuditoryOddball'
'Conc_510_Y2_Asym_27730_GoNoGo'
'Conc_510_Y2_Baseline_27855_AuditoryOddball'
'Conc_510_Y2_Baseline_27855_GoNoGo'
'Conc_510_Y2_Mid_27632_AuditoryOddball'
'Conc_510_Y2_Mid_27632_GoNoGo'
'27135_AuditoryOddball'
'27260_AuditoryOddball'
'27325_AuditoryOddball'
'27459_AuditoryOddball'
'27430_AuditoryOddball'
'27430_GoNoGo'
'TS#27371'
'TS#27430'
'TS#27487'
'TS#27636'
'TS#27708'
'TS#27391'
'TS#27419'
'TS#27623'
'TS#27647'
'TS#25658'
'TS#25707'
'TS#25897'
'TS#27059'
'TS#27143'
'TS#27589'
'TS#27631'
'TS#27762'
'TS#27797'
'TS#25762'
'TS#27204'
'TS#27253'
'TS#27274'
'25874'
'TS#27075'
'TS#27131'
'TS#27167'
'TS#27345'
'TS#27489'
'TS#27516'
'TS#27518'
'TS#27732'
'27090_AuditoryOddball'
'27268_AuditoryOddball'
'Other - TS#27505'
'Other - TS#27775 - Other'
'Other -TS#27423'
'TS#27021 - Baseline'
'TS#27091'
'TS#27315 -Asym'
'TS#27475'
'TS#27484'
'TS#27642'
'TS#27665'
'TS#27759'
'TS#25672'
'TS#25843'
'TS#27156'
'TS#27279'
'TS#27314'
'TS#27404'
'TS#27407'
'TS#27617'
'TS#27688'
'TS#27856'
'27558_AuditoryOddball'
'27702_AuditoryOddball'
'27714_AuditoryOddball'
'27745_AuditoryOddball'
'27798_AuditoryOddball'
'Other Files'
'27433_AuditoryOddball'
'27547_AuditoryOddball'
'27588_AuditoryOddball'
'27474_AuditoryOddball'
'27523_AuditoryOddball'
'27705_AuditoryOddball'
'Other Files'
'TS#27076'
'TS#27138'
'TS#27275'
'TS#27537'
'27336_AuditoryOddball'
'27533_AuditoryOddball'
'27614_AuditoryOddball'
'27669_AuditoryOddball'
'27862_AuditoryOddball'
'Other Files'
'27335_AuditoryOddball'
'27445_AuditoryOddball'
'27467_AuditoryOddbal'
'27683_AuditoryOdddball'
'27755_AuditoryOddball'}
I am trying to extract the series of 5 numbers from the cell and store it into an array. Such that the results from the first 5 results would be
[27730;
27730;
27855;
27855;
27632;]
I know that I can use @cellfun to scan if there is a specific number within a cell
find(cell2mat(c)==2)
However, this method won't work here. I would appreciate any guidance/help.
Thanks,
  2 Kommentare
Image Analyst
Image Analyst am 15 Aug. 2017
Whatever you posted on some third party website, paste here instead.
To get the results from the k'th cell of the cell array, use braces:
cellContents = c{k}; % Extract k'th cell into double array.
Patrick
Patrick am 15 Aug. 2017
My apologies, changes made accordingly

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Guillaume
Guillaume am 15 Aug. 2017
Bearbeitet: Guillaume am 15 Aug. 2017
It's not clear exactly what pattern you're looking for. The following will work for your first five numbers:
str2double(regexp(yourcellarray, '\d+(?=[^0-9]*$)', 'match', 'once'))
but so would many other patterns which would produce different results for the rest of the array.
Note: rather than using an external service, paste an excerpt of your cell array into your question.
  1 Kommentar
Patrick
Patrick am 15 Aug. 2017
I removed the pastebin link. This worked perfectly and is just what I needed.
Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by