Fig images not readable
29 views (last 30 days)
Show older comments
Hi,
I've encountered a major problem with the fig files produced with this script:
function [SNR_dB_C1, PhaseNoise_mean_C1, SNR_dB_C2, PhaseNoise_mean_C2] = Misura_SNR_con_CORE(FullName, Figure_path)
close all;
% =====================
% LETTURA DEL FILE DATI
% =====================
ApplicationDir = GetExecutableFolder();
% Lettura Header e handle al file dati
[Header, RSR_fid] = RSR_ReadHeader(FullName, ApplicationDir);
% -------------------------------------------------------------------------------------------------------------------------------------------------------------
% Frame Iniziale e Finale di Elaborazione
FirstFrame = Header.N_Frame-1;
FinalFrame = Header.N_Frame;
% -------------------------------------------------------------------------------------------------------------------------------------------------------------
% Allocazione Memoria Dato Raw per Singolo Frame
Frame_RawData = [];
for i = 1:Header.N_SubFrame
Frame_RawData = cat(1,Frame_RawData,{complex(zeros([1 Header.SubFrameLen_Sample_nelTempo(i)]),zeros([1 Header.SubFrameLen_Sample_nelTempo(i)]))});
end
% -------------------------------------------------------------------------------------------------------------------------------------------------------------
% ---------------------------- %
% --- Ciclo di Lettura --- %
% ---------------------------- %
wwwO1 = [];
wwwC1 = [];
wwwO2 = [];
wwwC2 = [];
indexdataO1 = find(strcmp(Header.SubFrame_Type,'O1-NF'));
indexdataC1 = find(strcmp(Header.SubFrame_Type,'C1-NF'));
indexdataO2 = find(strcmp(Header.SubFrame_Type,'O2-NF'));
indexdataC2 = find(strcmp(Header.SubFrame_Type,'C2-NF'));
for i = 1:Header.N_Frame
%
% Individuazione Frame da Elaborare
ElaborationEnabled = (i >= FirstFrame) && (i <= FinalFrame);
%
% Acquisizione New Frame (se abilitata)
[Frame_RawData, ~] = AcquisizioneNewFrame_1p2(RSR_fid, Header, Frame_RawData, ElaborationEnabled);
if ~ElaborationEnabled, continue; end
%% semi-MAN 1
% Dato di Offset
aux = Frame_RawData{indexdataO1};
aux = imag(aux)+1i*real(aux);
aux = aux.*(2^-Header.Sample_FractBit);
wwwO1 = cat(3,wwwO1,aux);
% Dato di Calibrazione
aux = Frame_RawData{indexdataC1};
aux = imag(aux)+1i*real(aux);
aux = aux.*(2^-Header.Sample_FractBit);
wwwC1 = cat(3,wwwC1,aux);
%% semi-MAN 2
% Dato di Offset
aux = Frame_RawData{indexdataO2};
aux = imag(aux)+1i*real(aux);
aux = aux.*(2^-Header.Sample_FractBit);
wwwO2 = cat(3,wwwO2,aux);
% Dato di Calibrazione
aux = Frame_RawData{indexdataC2};
aux = imag(aux)+1i*real(aux);
aux = aux.*(2^-Header.Sample_FractBit);
wwwC2 = cat(3,wwwC2,aux);
end
fclose(RSR_fid);
% =====================
wwwC1 = wwwC1(Header.N_DeadSample_Start(indexdataC1)+1:end-Header.N_DeadSample_Stop(indexdataC1),:,:);
wwwO1 = wwwO1(Header.N_DeadSample_Start(indexdataO1)+1:end-Header.N_DeadSample_Stop(indexdataO1),:,:);
wwwC2 = wwwC2(Header.N_DeadSample_Start(indexdataC2)+1:end-Header.N_DeadSample_Stop(indexdataC2),:,:);
wwwO2 = wwwO2(Header.N_DeadSample_Start(indexdataO2)+1:end-Header.N_DeadSample_Stop(indexdataO2),:,:);
wwwC1 = squeeze(wwwC1);
wwwO1 = squeeze(wwwO1);
wwwC2 = squeeze(wwwC2);
wwwO2 = squeeze(wwwO2);
% Debug
ZP = 512;
w = repmat(chebwin(223,90)/sum(chebwin(223,90)),[1,size(wwwC1,2)]);
wwwC1f = (abs(fft(wwwC1.*w,ZP,1))).^2;
wwwC1f_mean = 10*log10(mean(wwwC1f,2));
wwwO1f = (abs(fft(wwwO1.*w,ZP,1))).^2;
wwwO1f_mean = 10*log10(mean(wwwO1f,2));
wwwC2f = (abs(fft(wwwC2.*w,ZP,1))).^2;
wwwC2f_mean = 10*log10(mean(wwwC2f,2));
wwwO2f = (abs(fft(wwwO2.*w,ZP,1))).^2;
wwwO2f_mean = 10*log10(mean(wwwO2f,2));
fs = 2083.333; %[KHz];
f = [0:ZP-1]/ZP*fs;
fig1 = figure('visible','off');
plot(f,wwwC1f_mean);
hold all;
plot(f,wwwO1f_mean);
grid on;
hold off;
title('GAIN & OFFSET - C1');
legend('GAIN', 'OFFSET');
xlabel('frequenza [kHz]');
ylabel('FFT [dBFS]');
ylim([-160 0]);
saveas(fig1,fullfile(Figure_path,'SNR_GAIN_OFFSET_C1'),'fig');
saveas(fig1,fullfile(Figure_path,'SNR_GAIN_OFFSET_C1'),'jpg'); %%Salvo l'immagine anche in formato jpeg per inserirla nel report
fig2 = figure('visible','off');
plot(f,wwwC2f_mean);
hold all;
plot(f,wwwO2f_mean);
grid on;
hold off;
title('GAIN & OFFSET - C2');
legend('GAIN', 'OFFSET');
xlabel('frequenza [kHz]');
ylabel('FFT [dBFS]');
ylim([-160 0]);
saveas(fig2,fullfile(Figure_path,'SNR_GAIN_OFFSET_C2'),'fig');
saveas(fig2,fullfile(Figure_path,'SNR_GAIN_OFFSET_C2'),'jpg'); %%Salvo l'immagine anche in formato jpeg per inserirla nel report
S_C1 = mean(abs(wwwC1(:)).^2);
Noise_C1 = mean(std(wwwO1,0,2).^2);
PhaseNoisef_C1 = std(fft(wwwC1.*w,ZP,1),0,2).^2;
PhaseNoise_mean_C1 = 10*log10((mean(PhaseNoisef_C1(150:200))*223)/Noise_C1);
S_C2 = mean(abs(wwwC2(:)).^2);
Noise_C2 = mean(std(wwwO2,0,2).^2);
PhaseNoisef_C2 = std(fft(wwwC2.*w,ZP,1),0,2).^2;
PhaseNoise_mean_C2 = 10*log10((mean(PhaseNoisef_C2(150:200))*223)/Noise_C2);
SNR_C1 = S_C1 / Noise_C1;
SNR_dB_C1 = 10*log10(SNR_C1);
SNR_C2 = S_C2 / Noise_C2;
SNR_dB_C2 = 10*log10(SNR_C2);
% Stdout output for .exe parsing
fprintf("%f\n",SNR_dB_C1);
fprintf("%f\n",PhaseNoise_mean_C1);
fprintf("%f\n",SNR_dB_C2);
fprintf("%f",PhaseNoise_mean_C2);
close all;
end
The script is compiled into an executable with Matlab 2019b and run on a PC with the MATLAB Runtime 9.7 runtime environment. The Fig files don't work.
Trying to open them on a PC with just the runtime or even with the full Matlab 2019b doesn't work; no images are displayed. Sometimes an error dialog box appears:

Obviously, the corresponding jpg file works.
Before compiling it into an executable, the code ran perfectly, and the resulting fig files worked.
I'm attaching jpg and fig files for checking/comparation.
Best regards,
Mike
0 Comments
Answers (1)
Stephen23
on 15 Sep 2025 at 10:46
Edited: Stephen23
on 15 Sep 2025 at 11:20
MathWorks explicitly documents savefig as the modern way to write FIG files compatible with R2014b+ (and it’s fine to call from deployed code). Replace these four lines:
saveas(fig1,fullfile(Figure_path,'SNR_GAIN_OFFSET_C1'),'fig');
saveas(fig1,fullfile(Figure_path,'SNR_GAIN_OFFSET_C1'),'jpg');
saveas(fig2,fullfile(Figure_path,'SNR_GAIN_OFFSET_C2'),'fig');
saveas(fig2,fullfile(Figure_path,'SNR_GAIN_OFFSET_C2'),'jpg');
with this:
% Ensure graphics are fully realized before saving
drawnow;
% Save modern, compact FIGs (robust when created from deployed code)
savefig(fig1, fullfile(Figure_path,'SNR_GAIN_OFFSET_C1.fig'), 'compact');
saveas (fig1, fullfile(Figure_path,'SNR_GAIN_OFFSET_C1.jpg'));
savefig(fig2, fullfile(Figure_path,'SNR_GAIN_OFFSET_C2.fig'), 'compact');
saveas (fig2, fullfile(Figure_path,'SNR_GAIN_OFFSET_C2.jpg'));
3 Comments
Walter Roberson
on 17 Sep 2025 at 12:59
Anyway I don't know if there's a way to store the image into a fig file as visible without actually showing it.
NO
By the way, you can do
fig = openfig('IMMAGINE.fig', 'visible');
instead of setting visible on after the openfig.
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!