Reputation: 43
Is there a way of reading a text file to a cell array of strings and write it into excel file ?
i try something like this :
for d = 1:n
dFile(d,1) = d
content = strcat(dirpathstr{d})
filecontent =textscan(content, '%s', 'whitespace', '')
dFile(d,2) = filecontent
end
but it give me error "Conversion to cell from double is not possible", then i improve it with
"dFile(d,2) = str2double (filecontent)"
but its give me 'NaN' as result,
can anyone help me :)
Upvotes: 1
Views: 1727
Reputation: 14316
The variable dFile
is a double array, i.e. it only contains numbers. The first column always contains d
, which is a number - that's fine.
The textscan
function however returns a cell array. With the line
dFile(d,2) = filecontent
you try to take the cell array and save it inside the double array. This is not possible, as they are different data types. That is exactly what MATLAB tells you:
Conversion to cell from double is not possible
In your case, you don't need dFile
to be a double array, you can just make it a cell array too. Then you can assign filecontent
to dFile
, as they are of the same data type.
for d = 1:n
dFile{d,1} = d
content = strcat(dirpathstr{d})
filecontent =textscan(content, '%s', 'whitespace', '')
dFile{d,2} = filecontent
end
Upvotes: 1