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?
yes of course.
Azzi Abdelmalek
2013 年 8 月 3 日
編集済み: Azzi Abdelmalek
2013 年 8 月 3 日
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.
Azzi Abdelmalek
2013 年 8 月 3 日
編集済み: Azzi Abdelmalek
2013 年 8 月 3 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
