Saving to text file from cell array
2 views (last 30 days)
Show older comments
Dear colleagues,
we have a cell array like the one below, we obtained from a txt file:
[34] [12] 'xxx'
[3] [1] 'www'
[21] [2] 'qwe'
[11] [12] 'awk'
[34] [x] 'sed'
we just want to save it as a matrix text file with the same dimensions once again, afer having applied some replacement loops.
dlmwrite doesn't work (we're not dealing with matrixes)
save has unsupported Ascii..
fprintf ! It's the whole day we're struggling with it. Here is our code:
column1 = num2cell(colum1_from_txtfile)
column2 = num2cell(colum2_from_txtfile)
column3 = cellstr(colum3_from_txtfile)
M = [column1 column2 column3]
% our loops
fid = fopen('another_txtfile', 'wt')
fprintf(fid, '%d%d%s\t\n', M)
??? Error using ==> fprintf
Function is not defined for 'cell' inputs.
We guess the whole problem is about the value types we're using in the fprintf argument (%s %d ..).
We would be absolutely happy if anybody could provide as with suggestions!
Best,
Udiubu & Co.
1 Comment
Walter Roberson
on 5 Mar 2012
Is this a different question than your earlier http://www.mathworks.com/matlabcentral/answers/31231-txt-file-to-cell-array-to-text-file
?? If so then it would be best to indicate the difference, as otherwise someone is likely to mark it as a duplicate question that requires merging.
Answers (2)
Walter Roberson
on 5 Mar 2012
for K = 1 : size(M,1)
fprintf(fid, '%d%d%s\t\n', M{K,:});
end
0 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!