从双转换到单元是不可能的 – MATLAB
有没有办法将文本文件读取到string的单元格数组,并将其写入Excel文件?
我尝试这样的事情:
for d = 1:n dFile(d,1) = d content = strcat(dirpathstr{d}) filecontent =textscan(content, '%s', 'whitespace', '') dFile(d,2) = filecontent end
但它给我错误“从双转换到单元格是不可能的”,然后我改进它
"dFile(d,2) = str2double (filecontent)"
但是结果给了我'NaN'
谁能帮我 :)
variablesdFile
是一个双数组,即只包含数字。 第一列总是包含d
,这是一个数字 – 没关系。
textscan
函数返回一个单元格数组。 随着线路
dFile(d,2) = filecontent
您尝试采取单元格数组并将其保存在双数组中。 这是不可能的,因为它们是不同的数据types。 这正是MATLAB告诉你的:
从双转换到单元格是不可能的
在你的情况下,你不需要dFile
是一个双数组,你也可以将它作为一个单元格数组。 然后,您可以将filecontent
分配给dFile
,因为它们具有相同的数据types。
for d = 1:n dFile{d,1} = d content = strcat(dirpathstr{d}) filecontent =textscan(content, '%s', 'whitespace', '') dFile{d,2} = filecontent end