Saving to text file from cell array

2 次查看(过去 30 天)
Ubu
Ubu 2012-3-5
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 个评论
Walter Roberson
Walter Roberson 2012-3-5
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.

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2012-3-5
for K = 1 : size(M,1)
fprintf(fid, '%d%d%s\t\n', M{K,:});
end

Ubu
Ubu 2012-3-5
Hi Walter,
Sorry to have made some caos with duplicates.
Indeed, we also thought about a loop over the first dimension, but we get some random ordering of different sizes of numbers and letters, like below:
34 12 x
120(which is 'x' in Ascii, we assume) 120 3 1
119 119 21
Thanks for your kind help.
Best,
U-

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by