How to read specific cell arrays which consist of numeric and text values?

Home Forums New to Matlab How to read specific cell arrays which consist of numeric and text values?

This topic contains 6 replies, has 2 voices, and was last updated by  prada シューズ 9 months, 4 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2628

    mmenvo

    I want to read (in matlab) specific characters from a cell which contains a mixture of numbers and texts.  How can i do that in matlab? Could anybody help me with codes, please.

    Here is the example:

     

    r1200i000-0ln140010.LID

    This represents  a mixture of characters in a particular cell. I have more than such 100000 rows (cells) in single column. I want to read the 14th and 15 th character (here 14th is 1 and 15th is 4) and write this value in a different column in the same row.

     

    I have used the following codes:

    —————————————————————–

    v = {xlsread(‘test data.xlsx’, ‘A2:A165238′)};

    out=cellfun(@(x) str2num(x(14:15)),v,’un’,0);

    —————————————————————–

    Still matlab shows errors: ??? Index exceeds matrix dimensions. Error in ==> @(x)str2num(x(14:15))

    ??? Error using ==> cellfun

    Input #2 expected to be a cell array, was double instead.

    #2945

    Eric Verner
    Member

    mmenvo,

    I was able to get it to work by just removing the last two arguments from cellfun. I created v from the command line instead of reading it in, though.

    v = {‘r1200i000-0ln140010.LID’; ‘r1200i000-0ln240010.LID’};

    out=cellfun(@(x) str2num(x(14:15)),v)

    out =

    14
    24

    -Eric

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Bookmark and Share