Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何访问单元格数组中的字符串?_String_Matlab_Cell_Cells - Fatal编程技术网

String 如何访问单元格数组中的字符串?

String 如何访问单元格数组中的字符串?,string,matlab,cell,cells,String,Matlab,Cell,Cells,我读了matlab的帮助,仍然有一些问题- 对于单元格数组中的字符串-我只想输入字符串的前两个字符,如何才能做到这一点 'anscell{1,1}= ' 'LThand.jpg' 'aa1=strcmp('LT',anscell{1:5,1}(1:2));' 因为现在我犯了个错误- Bad cell reference operation. 'Error in a (line 5)' aa1=strcmp({'LT'},anscell{1:5,1}(1:2)); ans

我读了matlab的帮助,仍然有一些问题-

对于单元格数组中的字符串-我只想输入字符串的前两个字符,如何才能做到这一点

 'anscell{1,1}= '
 'LThand.jpg'
 'aa1=strcmp('LT',anscell{1:5,1}(1:2));'
因为现在我犯了个错误-

   Bad cell reference operation.
  'Error in a (line 5)'
   aa1=strcmp({'LT'},anscell{1:5,1}(1:2));

anscell
只有一个元素,其中包含字符串

因此,你应该写

aa1 = strcmp('LT',anscell{1}(1:2));
仅比较前两个字符的另一种方法是

aa1 = strncmp('LT',anscell{1},2);
由于
strncmp
也适用于单元格数组,因此您甚至可以删除索引,即

aa1 = strncmp('LT',anscell,2);