Unopenable .fig file
1 次查看(过去 30 天)
显示 更早的评论
I am updating my code from a script to a live script, and I want to use a function to plot graphs. When run in the script, the code maximises the figures and then saves them as both .fig and .jpg files. I have copied electronically the code from the script to the function, and, on running the live script, Matlab produces reconizable, but messed-up figures in the output pane. Both types of files (.fig and .jpg) can then be seen in the apprpopriate folder in both Matlab and File Explorer. However, I cannot open the .fig file from either Matlab or File Explorer. I can open the .jpg file, which contains the same image as the recognizable, but messed-up item in the Matlab Live Script output pane. I have entered the code and the results below. (Unfortunately, I cannot find a way of displaying Matlab .fig files here.) What am I doing wrong?
David.
Image (jpg) produced by original script:
Image produced by live script:
Code from original script:
%% This section plots the BM velocity transfer function with frequency and position as parameters without and with a bubble.
for pf=1:3
xx=PF(pf,1)/1000;
fx=PF(pf,2);
for Case=[1:6 11]
Fn=find(abs(f-fx)<((fmax/fmin)^(1/FN)-1)*0.5*fx);
fn=Fn(1);
f=(logspace(log10(fmin),log10(fmax),FN));
Xn=find(abs(x-xx)<Delta/1.99);
xn=Xn(1);
if Case <= 6
Fig=5+3*pf;
Stringy=' with 115 dB nHL at Ear Canal';
Stringt='With_and_without_a_point_bubble';
Maxx=max(vBdB(:,fn,1:6),[],'all');
Maxf=max(vBdB(xn,:,1:6),[],'all');
end
if Case==11
Fig=7+3*pf;
Stringy='relative to round window velocity';
Stringt='Excitation_from_stapes_and_RW';
Maxx=max(vBdB(:,fn,[1 2 11]),[],'all');
Maxf=max(vBdB(xn,:,[1 2 11]),[],'all');
end
figure(Fig)
subplot(2,2,1)
grid on
plot(1000*x,vBdB(:,fn,Case),Line(Case),'LineWidth',Rule(Case),'Color',Colour(Case))
hold on
if Case==11%(Case==10)||(Case==11)
for Cases=1:2
figure(Fig)
subplot(2,2,1)
plot(1000*x,vBdB(:,fn,Cases),Line(Cases),'LineWidth',Rule(Cases),'Color',Colour(Cases))
end
end
axis([0 35 Maxx-70 Maxx])
Stringf=num2str(f);
title(['Basilar Membrane Velocity -',Stringt,newline,Stringy,sprintf(', at %0.0f Hz,',fx)],'Interpreter','none','FontSize',18)
ylabel(['Basilar Membrane velocity amplitude (dB)',newline,'relative to 1 m/s'],'FontSize',14,'FontWeight','bold','Interpreter','none')
xlabel('\fontsize{24}Distance from Stapes (mm)')%lgd.Title.String = 'Frequency (kHz)';
subplot(2,2,3)
grid on
plot(1000*x,unwrap(angle(vB(:,fn,Case)))/2/pi,Line(Case),'LineWidth',Rule(Case),'Color',Colour(Case))%[(Case-1),0,2-Case])
hold on
if (Case==10)||(Case==11)
for Cases=1:2
figure(Fig)
subplot(2,2,3)
plot(1000*x,unwrap(angle(vB(:,fn,Cases)))/2/pi,Line(Cases),'LineWidth',Rule(Cases),'Color',Colour(Cases))
end
end
axis tight
Stringf=num2str(f);
ylabel(['Basilar Membrane velocity phase (cycles)',newline,'relative to excitation source'],'FontSize',14,'FontWeight','bold','Interpreter','none')
xlabel('\fontsize{24}Distance from Stapes (mm)')%lgd.Title.String = 'Frequency (kHz)';
figure(Fig)
subplot(2,2,2)
grid on
semilogx(f,vBdB(xn,:,Case),Line(Case),'LineWidth',Rule(Case),'Color',Colour(Case))
hold on
if Case==11
for Cases=1:2
figure(Fig)
subplot(2,2,2)
semilogx(f,vBdB(xn,:,Cases),Line(Cases),'LineWidth',Rule(Cases),'Color',Colour(Cases))
end
end
% axis([20 20000 -40 20])
% xlim([20 20000])
% ylim([-2 2])
axis([fmin fmax Maxf-70 Maxf])
% ax = gca;
% ax.XAxis.FontSize = 12;
% ax.YAxis.FontSize = 12;
Stringf=num2str(f);
% title(strcat('\fontsize{14} Basilar Membrane Velocity Transfer Function, Excitation @',Stringt,sprintf('\n Distance from stapes = %0.0f mm,',1000*xx),Comp))
title(['Basilar Membrane Velocity -',Stringt,newline,Stringy,sprintf(', at %0.0f mm,',xx*1000)],'Interpreter','none','FontSize',18)
% title(strcat('\fontsize{18} Basilar Membrane Velocity Transfer Function, Excitation @',Stringt,sprintf('\n Frequency = %0.0f Hz,',f(fn)),Comp))
% ylabel(strcat('\fontsize{14}Basilar Membrane velocity amplitude (dB)',Stringy))
ylabel(['Basilar Membrane velocity amplitude (dB)',newline,'relative to 1 m/s'],'FontSize',14,'FontWeight','bold','Interpreter','none')
xlabel('\fontsize{24}Frequency (Hz)')%lgd.Title.String = 'Frequency (kHz)';
% hold on
subplot(2,2,4)
grid on
semilogx(f,unwrap(angle(vB(xn,:,Case)))/2/pi,Line(Case),'LineWidth',Rule(Case),'Color',Colour(Case))
hold on
if (Case==10)||(Case==11)
for Cases=1:2
figure(Fig)
subplot(2,2,4)
semilogx(f,unwrap(angle(vB(xn,:,Cases)))/2/pi,Line(Cases),'LineWidth',Rule(Cases),'Color',Colour(Cases))
end
end
axis tight
% ax = gca;
% ax.XAxis.FontSize = 12;
% ax.YAxis.FontSize = 12;
Stringf=num2str(f);
% ylabel(strcat('\fontsize{14}Basilar Membrane velocity phase (cycles)',Stringy))
ylabel(['Basilar Membrane velocity phase (cycles)',newline,'relative to excitation source'],'FontSize',14,'FontWeight','bold','Interpreter','none')
xlabel('\fontsize{24}Frequency (Hz)')%lgd.Title.String = 'Frequency (kHz)';
if Case ==6
legend('Normal','Implant','Bubble at 0 mm','Bubble at 10 mm','Bubble at 20 mm','Bubble at 30 mm','Location','southwest','Orientation','Vertical');
end
if Case==10
legend('Excitation at 0 mm, stiff RW','Excitation at 10 mm, stiff RW','Excitation at 20 mm, stiff RW','Excitation at 30 mm, stiff RW','Normal stapes excitation','Stapes excitation with stiff RW','Location','southwest','Orientation','Vertical');
end
if Case ==11
legend('Actuator at 0 mm','Normal','Implant','Location','southwest','Orientation','Vertical');
end
if(Case==6)||(Case==10)||(Case==11)
Filename=strcat(Stringt,sprintf('_vB_%umm%uHz',xx*1000,fx),File);
set(gcf,'WindowState','maximized')
saveas(gcf,Filename,'fig')
saveas(gcf,Filename,'jpg')
end
end
end
Code in function:
function Plot(PF,FN,f,fmax,fmin,x,Delta,vB,vBdB,File,Line,Rule,Colour)
%% This section plots the BM velocity transfer function with frequency and position as parameters without and with a bubble.
for pf=1:3
xx=PF(pf,1)/1000;
fx=PF(pf,2);
for Case=[1:6 11]
% f=(logspace(log10(fmin),log10(fmax),FN));
Fn=find(abs(f-fx)<((fmax/fmin)^(1/FN)-1)*0.5*fx);
fn=Fn(1);
Xn=find(abs(x-xx)<Delta/1.99);
xn=Xn(1);
if Case <= 6
Fig=5+3*pf;
Stringy=' with 115 dB nHL at Ear Canal';
Stringt='With_and_without_a_point_bubble';
Maxx=max(vBdB(:,fn,1:6),[],'all');
Maxf=max(vBdB(xn,:,1:6),[],'all');
end
if Case==11
Fig=7+3*pf;
Stringy='relative to round window velocity';
Stringt='Excitation_from_stapes_and_RW';
Maxx=max(vBdB(:,fn,[1 2 11]),[],'all');
Maxf=max(vBdB(xn,:,[1 2 11]),[],'all');
end
figure(Fig)
subplot(2,2,1)
grid on
plot(1000*x,vBdB(:,fn,Case),Line(Case),'LineWidth',Rule(Case),'Color',Colour(Case))
hold on
if Case==11%(Case==10)||(Case==11)
for Cases=1:2
figure(Fig)
subplot(2,2,1)
plot(1000*x,vBdB(:,fn,Cases),Line(Cases),'LineWidth',Rule(Cases),'Color',Colour(Cases))
end
end
axis([0 35 Maxx-70 Maxx])
Stringf=num2str(f);
title(['Basilar Membrane Velocity -',Stringt,newline,Stringy,sprintf(', at %0.0f Hz,',fx)],'Interpreter','none','FontSize',18)
ylabel(['Basilar Membrane velocity amplitude (dB)',newline,'relative to 1 m/s'],'FontSize',14,'FontWeight','bold','Interpreter','none')
xlabel('\fontsize{24}Distance from Stapes (mm)')%lgd.Title.String = 'Frequency (kHz)';
subplot(2,2,3)
grid on
plot(1000*x,unwrap(angle(vB(:,fn,Case)))/2/pi,Line(Case),'LineWidth',Rule(Case),'Color',Colour(Case))%[(Case-1),0,2-Case])
hold on
if (Case==10)||(Case==11)
for Cases=1:2
figure(Fig)
subplot(2,2,3)
plot(1000*x,unwrap(angle(vB(:,fn,Cases)))/2/pi,Line(Cases),'LineWidth',Rule(Cases),'Color',Colour(Cases))
end
end
axis tight
Stringf=num2str(f);
ylabel(['Basilar Membrane velocity phase (cycles)',newline,'relative to excitation source'],'FontSize',14,'FontWeight','bold','Interpreter','none')
xlabel('\fontsize{24}Distance from Stapes (mm)')%lgd.Title.String = 'Frequency (kHz)';
figure(Fig)
subplot(2,2,2)
grid on
semilogx(f,vBdB(xn,:,Case),Line(Case),'LineWidth',Rule(Case),'Color',Colour(Case))
hold on
if Case==11
for Cases=1:2
figure(Fig)
subplot(2,2,2)
semilogx(f,vBdB(xn,:,Cases),Line(Cases),'LineWidth',Rule(Cases),'Color',Colour(Cases))
end
end
% axis([20 20000 -40 20])
% xlim([20 20000])
% ylim([-2 2])
axis([fmin fmax Maxf-70 Maxf])
% ax = gca;
% ax.XAxis.FontSize = 12;
% ax.YAxis.FontSize = 12;
Stringf=num2str(f);
% title(strcat('\fontsize{14} Basilar Membrane Velocity Transfer Function, Excitation @',Stringt,sprintf('\n Distance from stapes = %0.0f mm,',1000*xx),Comp))
title(['Basilar Membrane Velocity -',Stringt,newline,Stringy,sprintf(', at %0.0f mm,',xx*1000)],'Interpreter','none','FontSize',18)
% title(strcat('\fontsize{18} Basilar Membrane Velocity Transfer Function, Excitation @',Stringt,sprintf('\n Frequency = %0.0f Hz,',f(fn)),Comp))
% ylabel(strcat('\fontsize{14}Basilar Membrane velocity amplitude (dB)',Stringy))
ylabel(['Basilar Membrane velocity amplitude (dB)',newline,'relative to 1 m/s'],'FontSize',14,'FontWeight','bold','Interpreter','none')
xlabel('\fontsize{24}Frequency (Hz)')%lgd.Title.String = 'Frequency (kHz)';
% hold on
subplot(2,2,4)
grid on
semilogx(f,unwrap(angle(vB(xn,:,Case)))/2/pi,Line(Case),'LineWidth',Rule(Case),'Color',Colour(Case))
hold on
if (Case==10)||(Case==11)
for Cases=1:2
figure(Fig)
subplot(2,2,4)
semilogx(f,unwrap(angle(vB(xn,:,Cases)))/2/pi,Line(Cases),'LineWidth',Rule(Cases),'Color',Colour(Cases))
end
end
axis tight
% ax = gca;
Function call from live script:
Plot(PF,FN,f,fmax,fmin,x,Delta,vB,vBdB,File,Line,Rule,Colour)
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!