How to save all my matlab plots from for loop?
12 ビュー (過去 30 日間)
古いコメントを表示
Hello Everyone,
I am trying to save all my plots from my for loop into a word document. I have tried using save2word, but that only saves the last figure from the for loop. If anyone can give me some insight on what I can add to my script, such that I am able to export all plots from MATLAB into a Word doc. It will be most appreciated.
Also, I tried using the print function, and that didn't work for me yet either.
Sincerely,
Robert
CODE:
fName = 'SHOCK2019Graphs.doc'
if exist(fName,'file')
delete(fName)
end
wordHand = save2Word(fName);
for q = 1:16
figure(q)
plot(SBOB{1}.tt,SBOB{1}.Acc(:,q))
hold on
plot(SBridge{5}.tt,SBridge{5}.Acc(:,q))
title(SBOB{1}.labels(q)),xlabel('Time, Measured in Seconds'), ylabel('Acceleration, Measured in ft/sec^2')
legend('Bridge on Box','Bridge','location','northeast')
filename = 'Test.pdf';
print(figure(q),'-dpdf',filename);
end
save2Word(fName,wordHand)
採用された回答
Jon
2019 年 9 月 23 日
編集済み: Jon
2019 年 9 月 23 日
I would recommend using the standard MATLAB function saveas (type doc saveas on the command line for help)
Specifically inside of your for loop right after you make your plot insert something like
filename = ['plot',num2str(q),'.emf'] % plot names plot1.emf, plot2.emf ...
saveas(gcf,filename,'meta') % save as .emf file
In the above I saved as .emf file. I find these work well for including into word but you could use other formats instead.
Note once you have these figure files you will have to manually insert them into your word document.
2 件のコメント
Jon
2019 年 9 月 23 日
編集済み: Jon
2019 年 9 月 23 日
Glad that worked for you. I'm not sure exactly what your workflow looks like, but I find that I usually want to insert the figures at specific locations within my Word document within some section of explanatory text. So I usually end up pulling them in one at a time anyhow as I get to them in the write up.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Specifying Target for Graphics Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!