brucezepplin
brucezepplin

Reputation: 9752

need to convert char to cell array

Hi I have the following object in matlab:

class(data{1}) =

    char

which is stored in

class(data) =

    cell

however I am trying to call:

[estt,este]  = hmmtrain(data{1},e,t);

and get an error:

??? Error using ==> hmmtrain at 209
Seqs must be cell array or numerical array.

Is there a way to make each element of data compatible with the hmmtrain function?

thanks very much

Upvotes: 0

Views: 4406

Answers (1)

chappjc
chappjc

Reputation: 30579

For your sequence, data{1} is a char array, so convert each character into it's ASCII code via double:

[estt,este]  = hmmtrain(double(data{1}),e,t);

If you want to feed hmmtrain multiple sequences with the option of using a cell array for the first input argument (as it looks like you many want to with data being a cell) try the following,

dataNumCell = cellfun(@double,data,'UniformOutput',false);
[estt,este]  = hmmtrain(dataNumCell,e,t);

EDIT: Updated multiple sequence option where hmmtrain had extra double.

Upvotes: 2

Related Questions