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 Matlab字符到字符串的转换问题。使用什么功能?_String_Matlab_Char_String Formatting_Strcat - Fatal编程技术网

String Matlab字符到字符串的转换问题。使用什么功能?

String Matlab字符到字符串的转换问题。使用什么功能?,string,matlab,char,string-formatting,strcat,String,Matlab,Char,String Formatting,Strcat,x(1)是1,x(2)是2,依此类推。。。中间有5个空格。。 尺寸(x)=123 一行23列 我试过使用num2str和strcat,但我不能使用这些号码。 y=num2str(x),y=strcat(x) 我希望是。。x(1)=1234,x(2)=56789,x(3)=7654 我应该使用什么函数来完成上述任务?有几种方法可以实现您想要的功能。其中之一是斯特克 x = 1234 56789 7654 简单的解决方案是使用sscanf: x = '1234 56789

x(1)是1,x(2)是2,依此类推。。。中间有5个空格。。 尺寸(x)=123 一行23列 我试过使用num2str和strcat,但我不能使用这些号码。 y=num2str(x),y=strcat(x)

我希望是。。x(1)=1234,x(2)=56789,x(3)=7654


我应该使用什么函数来完成上述任务?

有几种方法可以实现您想要的功能。其中之一是斯特克

x = 1234     56789     7654

简单的解决方案是使用
sscanf

x = '1234     56789     7654';
[fst rest] = strtok(x,' ');
适用于此任务:

x =' 1234     56789     7654'

sscanf(x, '%d')

ans =

    1234
   56789
    7654
>>x='1234567897654'; >>x=str2num(x)' x= 1234 56789 7654
只是为了给这个组合添加另一个答案

>> x = '1234 56789 7654'; >> x = str2num(x)' x = 1234 56789 7654
下面创建一个字符串单元格数组,然后使用sscanf应用程序进行后续操作

y = textscan(x, '%d     %d     %d')

这将输出字符串而不是数字,并且只拆分一次。使用STR2NUM时要小心,因为它基于EVAL。更简单地说是:
y=textscan(x,'%d')。此外,您可能还应该添加
y=y{1}非常感谢!我真傻!我不知道!
b = regexp(x,'\d+','match');
y = cellfun(@(a) (sscanf(a,'%d')),b);