save fig "argument must be a fig file" error
19 views (last 30 days)
Show older comments
Why does this code not save my fig? save as works!
if 1 == 1
h = figure;
subplot(5,1,1)
plot(MatEfforts(5,:)*ell1/0.3048,(-MatEfforts(1,:)*ell1/0.3048*12)+(HoleSize)/2*ones(size(MatEfforts(1,:))) - MatEfforts(6,:)*ell1/0.3048*12,'r')
hold on
x = [0 MatEfforts(5,end)*ell1/0.3048 MatEfforts(5,end)*ell1/0.3048 0 ];
y = [(HoleSize+HoleOvergauge+0.2)/2*ones(1,2) (HoleSize+HoleOvergauge)/2*ones(1,2) ];
fill(x,y,'k')
x = [0 MatEfforts(5,end)*ell1/0.3048 MatEfforts(5,end)*ell1/0.3048 0 ];
y = [-(HoleSize+HoleOvergauge+0.2)/2*ones(1,2) -(HoleSize+HoleOvergauge)/2*ones(1,2)];
fill(x,y,'k')
plot(MatEfforts(5,:)*ell1/0.3048,(-MatEfforts(1,:)*ell1/0.3048*12)-(HoleSize)/2*ones(size(MatEfforts(1,:))) + MatEfforts(6,:)*ell1/0.3048*12,'r')
plot(MatEfforts(5,:)*ell1/0.3048,(-MatEfforts(1,:)*ell1/0.3048*12),'--r')
plot(MatEfforts(5,:)*ell1/0.3048,(-MatEfforts(1,:)*ell1/0.3048*12)+(HoleSize)/2*ones(size(MatEfforts(1,:))) - MatEfforts(7,:)*ell1/0.3048*12,':r')
plot(MatEfforts(5,:)*ell1/0.3048,(-MatEfforts(1,:)*ell1/0.3048*12)-(HoleSize)/2*ones(size(MatEfforts(1,:))) + MatEfforts(7,:)*ell1/0.3048*12,':r')
% plot([0 MatEfforts(5,end)*ell1/0.3048],(HoleSize+HoleOvergauge)/2*ones(1,2),'k')
% plot([0 MatEfforts(5,end)*ell1/0.3048],-(HoleSize+HoleOvergauge)/2*ones(1,2),'k')
xlim([0 MatEfforts(5,end)*ell1/0.3048])
xlim([0 Lplot])
ylim([-5 5])
title('Deflection')
%xlabel('Distance from bit face [ft]'),
ylabel('y [in]')
subplot(5,1,2)
plot(MatEfforts(5,:)*ell1/0.3048,-MatEfforts(1,:)*ell1/0.3048*12,'r')
plot(MatEfforts(5,:)*ell1/0.3048,(-MatEfforts(6,:)*ell1)/0.3048*12-HoleOvergauge/2,'k')
plot(MatEfforts(5,:)*ell1/0.3048,(MatEfforts(6,:)*ell1)/0.3048*12+HoleOvergauge/2,'k')
xlim([0 MatEfforts(5,end)*ell1/0.3048])
xlim([0 Lplot])
ylim([-5 5])
title('Relative Deflection')
%xlabel('Distance from bit face [ft]'),
ylabel('y [in]')
subplot(5,1,3)
plot(MatEfforts(5,:)*ell1/0.3048,MatEfforts(2,:)*180/pi, 'r')
xlim([0 MatEfforts(5,end)*ell1/0.3048])
xlim([0 Lplot])
title('Relative Inclination')
%xlabel('Distance from bit face [ft]'),
ylabel('S [deg]')
subplot(5,1,4)
plot(MatEfforts(5,:)*ell1/0.3048,MatEfforts(3,:)*Fstar*ell1/1000/4.44822/0.0254/12, 'r')
xlim([0 MatEfforts(5,end)*ell1/0.3048])
xlim([0 Lplot])
title('Moment')
%xlabel('Distance from bit face [ft]'),
ylabel('M [klbf-ft]')
subplot(5,1,5)
plot(MatEfforts(5,:)*ell1/0.3048,MatEfforts(4,:)*Fstar/1000/4.44822, 'r')
xlim([0 MatEfforts(5,end)*ell1/0.3048])
xlim([0 Lplot])
title('Shear')
xlabel('Distance from bit face [ft]'),
ylabel('T [klbf]')
%set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
saveas(gcf,[name,'-Effort','-DLS-',num2str(round(DLSeq)),'-Inc-',num2str(Theta/pi*180),'-SCE-',...
num2str(round(1/eta*100)),'%','-OG-', num2str(HoleOvergauge*100), '%', '-F-', num2str(Frss/4.44822),'-All.png'],'png')
savefig([name,'-Effort','-DLS-',num2str(round(DLSeq)),'-Inc-',num2str(Theta/pi*180),'-SCE-',num2str(round(1/eta*100)),'%','-OG-', num2str(HoleOvergauge*100), '%', '-F-', num2str(Frss/4.44822),'-All'])
end %Effort with real BHA
![save fig.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/236221/save%20fig.png)
0 Comments
Answers (1)
Rik
on 29 Aug 2019
Edited: Rik
on 29 Aug 2019
I would suggest using sprintf to generate the file name. Check if the precision parameters are set to what you mean. I assumed name is a char array.
Since you have the handle, why rely on gcf to grab the correct figure and give the user a chance to mess it up by selecting another figure?
long_name=[name,'-Effort','-DLS-',num2str(round(DLSeq)),'-Inc-',num2str(Theta/pi*180),'-SCE-',...
num2str(round(1/eta*100)),'%','-OG-', num2str(HoleOvergauge*100), '%', '-F-', num2str(Frss/4.44822),'-All'];
saveas(h,[longname '.png'],'png')
savefig(h,[longname '.fig'])
%%
%with sprintf:
long_name=sprintf('%s-Effort-DLS-%.0f-Inc-%.3f-SCE-%.0f%%-OG-%.1f%%-F-%.4f-All',...
name,DLSeq,Theta/pi*180,1/eta*100,HoleOvergauge*100,Frss/4.44822);
0 Comments
See Also
Categories
Find more on Printing and Saving 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!