Question

I have a variable called data that is a 5574x1 cell array. Currently, each element is an array of characters representing a sentence. I want to split each array on whitespace. So I tried doing this:

new_data = {strsplit(data{:})}

and Matlab gives me this error:

Error using strsplit (line 94)
Argument 'spam  Free entry in 2 a wkly comp to win FA Cup final tkts
21st May 2005. Text FA to 87121 to receive entry question(std txt
rate)T&C's apply 08452810075over18's' did not match any valid
parameter of the parser.

However, when I do this:

for x=1:5574
    d(x) = {strsplit(data{x})};
end

It works just fine. I can't seem to figure out what the difference between the two is. Why won't the first one work? Any help is appreciated.

Was it helpful?

Solution

By doing strsplit(data{:}), it passes each cell as a different argument, but strsplit needs the strings in a single argument. Try this instead:

new_data = strsplit(strjoin(data))

EDIT: Use strjoin instead of strvcat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top