strsplit:输入型'字符'函数未定义 [英] strsplit: undefined function for input type 'char'

查看:1504
本文介绍了strsplit:输入型'字符'函数未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个< 20X1>单元阵列和他们每个人存储在一个字符串形式的一些数据(因为它似乎我!)。我要访问的单元格中的每个元素作为一个单独的字符串,分裂是在口头上。

I have a <20x1> cell array and each of them stores some data in the form of a string (as it appears to me!!!). I want to access each element of the cell as an individual string and split is in words.

单元阵列我为&lt; 20X1>单元阵列,以及访问每个元素作为一个单元,我使用一个for循环

The cell array I have is <20x1> cell array and to access each element as a cell I am using a for loop.

for i=1:20
    line=newline{i}
end

它让我看到阵列中的所有元素。现在,因为线是一个字符串,我申请strsplit函数来获取字符串中的单词。

It shows me a all the elements within the array. Now since line is a string, I apply strsplit function to retrieve the words in the string.

for i=1:20
   words(i,:)=strsplit(line)
end

这给了我一个错误信息:

This gives me an error message :

??? Undefined function or method 'strsplit' for input
arguments of type 'char'.

Error in ==> chk at 15
words=strsplit(newline{i})

谁能解释一下我在哪里,我错了吗?任何帮助将AP preciated。先谢谢了。

can anyone explain me where I am wrong? Any help will be appreciated. Thanks in advance.

推荐答案

我的猜测是,你正在使用 Matlab的一个之前版本R2013a。尽管它们是通用的功能,应当有加蜂很久以前,<一个href=\"http://www.mathworks.com/help/releases/R2013a/matlab/ref/strsplit.html\"><$c$c>strsplit和<一个href=\"http://www.mathworks.com/help/releases/R2013a/matlab/ref/strjoin.html\"><$c$c>strjoin href=\"http://www.mathworks.com/help/matlab/release-notes.html#btr4jsl-1\">补充说。

My guess is that you're using a version of Matlab prior to R2013a. Despite the fact that they are generic functions and should have bee added ages ago, strsplit and strjoin were only added in this most recent version.

有几种方法可以解决,如果你想要做的就是拆分串入的话不能获得 strsplit 。如果你所有的空格都可以只使用简单的空间 strread 的是这样的:

There are several ways you can get around not having access to strsplit if all you want to do is split a string into words. If all of your whitespaces are simple spaces you can just use strread like this:

strread(line,'%s','delimiter',' ')

不过, textscan 应更加强劲:

However, textscan should be more robust:

textscan(line,'%s')

使用 正则表达式 还应是强大的,但很可能会更慢:

Using regexp should also be robust, but will likely be slower:

regexp(line,'\s+','split')

所有这些回报输出作为字符串(你的话)的电池阵列,就像 strsplit 。从 textscan 输出相对被置换成其他。

All of these return outputs as cell arrays of strings (your words), just like strsplit. The output from textscan is transposed relative to the others.

这篇关于strsplit:输入型'字符'函数未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆