write in text file
1 次查看(过去 30 天)
显示 更早的评论
i have to write a cell which has both numbers and strings in to a text file if i use %s the numeric values are not written properly. Can any one help Thanks in advance
0 个评论
采纳的回答
Wayne King
2012-11-6
You can use ischar() to query which elements are strings and write those properly.
4 个评论
Walter Roberson
2012-11-6
Letting C be your cell array, then:
TC = C;
cellisnum = ~cellfun(@ischar, TC);
TC(cellisnum) = cellfun(@num2str, TC(cellisnum), 'UniformOutput', false);
for R = 1 : size(TC,1)
fprintf(s, '%s ', TC{R,1:end-1));
fprintf(s, '%s\n', TC{R,end});
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!