problem using fprintf for writing cell data and global data at the same time.
显示 更早的评论
if ~ischar(fileName)
return;
end
fileID = fopen(fullfile(filePath, fileName), 'w');
cellArray=
'p.4004'
'p.4005'
'p.4007'
cellArray 3x1 cell global
matrix=[1 2 3;4 5 6;7 8 9]
%I can write these values separetely into word like this;
fprintf(fileID,'%47f %f \n',matrix')
fprintf(fileID,'%s\n',cellArray{:})
%but I need to write them together into microsoft word like this;
p.4004 1 2 3
p.4005 4 5 6
p.4007 7 8 9
采纳的回答
cellArray={'p.4004'
'p.4005'
'p.4007'}
matrix=[1 2 3;4 5 6;7 8 9]
v=[cellArray num2cell(matrix)]
fileID = fopen('fic13.txt', 'w');
for k=1:size(v,1)
fprintf(fileID, '%s %d %d %d\n', v{k,:});
end
fclose(fileID)
13 个评论
it gives this result;
p.4004 1 2 3 p.4005 4 5 6 p.4007 7 8 9
I want to create like this;
p.4004 1 2 3
p.4005 4 5 6
p.4007 7 8 9
That's what the code do. Have you copied it then run it?
open the file with wordpad, it's different from notepad
it cannot separate the p.'s and the numbers it writes them side to side.
i mean first column needs to be only p.'s and then the second and third columns includes numbers.
I opened microsoft word not note bloc.
Try this for notepad (\r\n)
cellArray={'p.4004'
'p.4005'
'p.4007'}
matrix=[1 2 3;4 5 6;7 8 9]
v=[cellArray num2cell(matrix)]
fileID = fopen('fic13.txt', 'w');
for k=1:size(v,1)
fprintf(fileID, '%s %d %d %d\r\n', v{k,:});
end
fclose(fileID)
it gives the same result sir.
What is your Operating System?
windows 7 64 bit, matlab 2012
I don't know what is the problem, when I run the same code, I'am getting the correct answer. Maybe you are checking the wrong file?
ok no problem, I'll try it again carefully, thank you so much for sparing your time.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
