Warning: Attempt to write an unsupported data type to an ASCII file. I have a data which its class cell and its attributes global. I wanna save and write this data into text but I give this warning.

4 views (last 30 days)
cellArray= '4004 638905.26736 4552506.2389'
% cellArray 1x1 188 cell global
startingFolder = 'C:\Program Files\MATLAB'
if ~exist(startingFolder, 'dir')
startingFolder = pwd
end
defaultFileName = fullfile(startingFolder, '*.txt')
[baseFileName, folder] = uiputfile(defaultFileName, 'Select a file')
if baseFileName == 0
return
end
fullFileName = fullfile(folder, baseFileName)
save(fullFileName, 'cellArray', '-ASCII')

Accepted Answer

Walter Roberson
Walter Roberson on 29 May 2013
save -ASCII files only support pure numeric elements. Cell arrays and strings are not pure numeric elements, and reading such a file back in with load -ASCII would not result in a cell array or string.
If you want to write a string to a file,
fid = fopen(fullFileName, 'wt');
fwrite(fid, cellArray); %cellArray is really a string confusingly named
fclose(fid)
Unless, that is, there are characters with position numbers beyond 255 to be written; writing such strings takes more work.
  2 Comments
Abdulaziz Abutunis
Abdulaziz Abutunis on 20 Jan 2017
Edited: Walter Roberson on 20 Jan 2017
Hi Walter I have a raw data with number, text and blank cells. I was able to read them form an Excel file.as follow
[numData textData rawData]= xlsread('FileName.xlsx','SheetName');
then I want to write this to a text file as follow
fid = fopen(FileName.txt, 'wt');
fwrite(fid, rawData);
fclose(fid)
However this did not work. I have MATLAB R2010a. The error was
??? Undefined function or variable 'FileName'.
Error in ==> Rotating_and_Curving_Foils at 153
fid = fopen(FileName.txt, 'wt');

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!