How can I convert a cell array with values {'S101' 'S102'},to a double array?

1 view (last 30 days)
events = {'S100';'S102';'S103';'S101'}
  3 Comments
Bubblesjinx
Bubblesjinx on 21 Aug 2018
@Walter expected result shoould be a double array with same entries, but i figured out if i eliminate 'S', it would work too.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 21 Aug 2018
Edited: Stephen23 on 21 Aug 2018
Making some assumptions:
>> events = {'S100';'S102';'S103';'S101'};
>> str2double(strrep(events,'S','')) % easy
ans =
100
102
103
101
>> sscanf(sprintf('%s\v',events{:}),'S%d\v') % probably more efficient
ans =
100
102
103
101

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!