How to save all my matlab plots from for loop?
Show older comments
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)
3 Comments
Walter Roberson
on 23 Sep 2019
Perhaps
fName = 'SHOCK2019Graphs.doc'
if exist(fName,'file')
delete(fName)
end
wordHand = save2Word(fName);
h = gcf;
ax = gca;
for q = 1:16
%figure(q)
plot(ax, SBOB{1}.tt,SBOB{1}.Acc(:,q))
hold(ax, 'on')
plot(ax, SBridge{5}.tt,SBridge{5}.Acc(:,q))
hold(ax, 'off')
title(ax, SBOB{1}.labels(q)),xlabel('Time, Measured in Seconds'), ylabel('Acceleration, Measured in ft/sec^2')
legend(ax, {'Bridge on Box','Bridge'},'location','northeast')
filename = 'Test.pdf';
print(fig,'-dpdf',filename);
save2Word(fName, filename);
end
Robert Flores
on 23 Sep 2019
Walter Roberson
on 23 Sep 2019
h = gcf;
ax = gca;
should have been
fig = gcf;
ax = gca(fig);
Accepted Answer
More Answers (0)
Categories
Find more on Language Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!