Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.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
Regex 在for循环中将字符串转换为数字时返回NaN_Regex_Matlab_For Loop_Cell Array - Fatal编程技术网

Regex 在for循环中将字符串转换为数字时返回NaN

Regex 在for循环中将字符串转换为数字时返回NaN,regex,matlab,for-loop,cell-array,Regex,Matlab,For Loop,Cell Array,单元1是37x71单元,单元2是37x71空单元 前 如果我单独运行上面循环的每个部分,那么函数将按预期工作。但是,当执行整个循环时,它将cln作为NaN返回 您得到的是NaN,因为您的正则表达式与Cell1的一个值不匹配,并返回一个空字符串(该字符串将str2double转换为NaN) 但是让我们后退一步。您可以在单元数组上使用,因此无需循环遍历所有元素。此外,您还可以使用a查找数字前面的“f”,从而防止使用regexp两次 Cell1{1,2} = -(f32.*x1.*x6)./v1

单元1是37x71单元,单元2是37x71空单元


如果我单独运行上面循环的每个部分,那么函数将按预期工作。但是,当执行整个循环时,它将
cln
作为NaN返回

您得到的是NaN,因为您的正则表达式与
Cell1
的一个值不匹配,并返回一个空字符串(该字符串将
str2double
转换为NaN)

但是让我们后退一步。您可以在单元数组上使用,因此无需循环遍历所有元素。此外,您还可以使用a查找数字前面的“f”,从而防止使用
regexp
两次

 Cell1{1,2} = -(f32.*x1.*x6)./v1

您得到的是NaN,因为您的正则表达式与
Cell1
的一个值不匹配,并返回一个空字符串(它将
str2double
转换为NaN)

但是让我们后退一步。您可以在单元数组上使用,因此无需循环遍历所有元素。此外,您还可以使用a查找数字前面的“f”,从而防止使用
regexp
两次

 Cell1{1,2} = -(f32.*x1.*x6)./v1

什么是
NaN错误
?Matlab中没有这种情况。错误是变量cln作为NanThats返回,因为出于某种原因,
rep2
不是数字字符串。什么是
NaN错误
?Matlab中没有这种情况。错误是变量cln作为一个字符串返回,因为出于某种原因,
rep2
不是一个数字字符串。
stringNumber = regexp(Cell1, '(?<=f)[0-9]*', 'match', 'once');
numbers = str2double(stringNumber);
Cell2 = cell(37, 71);
for k = 1:numel(numbers)
    row = mod(k - 1, size(Cell1, 2)) + 1;
    Cell2(row, numbers(k)) = Cell1(k);
end