Output argument 'PreCharge' is not assigned on some execution paths

1 visualizzazione (ultimi 30 giorni)
Hello,
I have a system in Simulink and I am getting the error;
"Output argument 'PreCharge' is not assigned on some execution paths"
Basically, when output signal PreCharge = 0, Upd1 = 1 and Simulink goes through the code in the function block. When PreCharge is 1, Upd1 = 0 and the code is therefore ignored for the rest of the simulation. I understand the error, because PreCharge is not declared outside of the if statement. However, I can't initialize the block outside of the if statement without it reiniatializing everytime it goes through the code. So I created a Base Workspace variable PreCharge with initial value = 0. I resolved the signal but I still get the error. The only way I can get it to work is to make it a global variable and I'm trying to avoid that.
My MatLAB Function block has the following code;
function [PreCharge,Red1,Yel] = CheckList(PSto,T,WFt,LoadR,ChargeEn,SCD,WiFiCommSig,EPOR,clk,Upd1)
.
.
.
if Upd1 == 1
disp('Check');
if clk > Update1 + 0.1
if WiFiCommSig == 0
WiFiLost = WiFiLost + clk - Update1;
else
WiFiLost = 0;
end
Update1 = clk;
if WiFiCommSig == 0 && WiFiLost > WFt
Check = 0;
disp('No Wireless Communication')
end
if Check == 1 && PS == PSto && clk > T;
PreCharge = double(1);
elseif Check == 0;
disp('Fault')
Red1 = 1;
else
disp('Updating')
end
InI = PS / LoadR;
end
end
end
  5 Commenti
Nicholas
Nicholas il 22 Lug 2013
Thank you for replying. The function is not being used anywhere else. I tested the Compare to Zero and enabled subsystem combo of blocks I mentioned earlier in a small system and they work the way I want so I don't believe they are the problem. Here is an updated look at my code. I stepped through it and once PreCharge = 1 the green arrow skips ahead elsewhere in the simulation. But PreCharge never changes and Upd1 is therefore never set to 0.
function [PreCharge,Red1,Yel] = CheckList(PSto,T,WFt,LoadR,ChargeEn,SCD,WiFiCommSig,EPOR,clk,Upd1)
if Upd1 == 1
disp('Check');
if clk > Update1 + 0.1
if WiFiCommSig == 0
WiFiLost = WiFiLost + clk - Update1;
else
WiFiLost = 0;
end
Update1 = clk;
if WiFiCommSig == 0 && WiFiLost > WFt
Check = 0;
disp('No Wireless Communication')
end
if Check == 1 && PS == PSto && clk > T;
PreCharge = 1;
elseif Check == 0;
disp('Fault')
Red1 = 1;
PreCharge = 0;
else
disp('Updating')
PreCharge = 0;
end
else
PreCharge = 0;
end
else
PreCharge = 1;
end
end
dpb
dpb il 22 Lug 2013
Well, there's nothing in the code that will change Upd1 (and it isn't returned if there were) so that's the part that isn't shown well enough to know what you expect to change it and why that isn't happening as you think it should.
One thing I do note in your function is that you have a logic test on
if Check == 1 && PS == PSto && clk > T;
but there's no path in the code that will ever set Check=1 unless it's GLOBAL.
Again, w/o a better overall picture of what you're trying to do can't really give an actual solution/suggestion. But, there's a logic flaw somewhere...

Accedi per commentare.

Risposta accettata

Nicholas
Nicholas il 23 Lug 2013
Sorry, I removed a large portion of the code to simplify it on here. Check is actually declared earlier in the function block. I believe I figured out the problem though. I think there was something wrong with the variable execution rate. After adding in a configuration from an old project it worked fine. Thank you both for trying to help.
  1 Commento
dpb
dpb il 23 Lug 2013
Yes, clearly the problem was something not shown...a difficulty especially w/ Simulink owing to the model structure not lending itself to posting as is code.
Glad you did find/resolve it...

Accedi per commentare.

Più risposte (1)

Heawa Mehmandoust
Heawa Mehmandoust il 24 Ott 2017
function [overall_snr, segmental_snr,segSNR] = Signal_to_Noise_Ratio(Speech, Enhanced_speech,sample_rate)
% ---------------------------------------------------------------------- % Check the length of the clean and processed speech. Must be the same. % ----------------------------------------------------------------------
clean_length = length(Speech); Enhanced_length = length(Enhanced_speech);
if (clean_length ~= Enhanced_length) disp('Error: Both Speech Files must be same length.'); return end
% ---------------------------------------------------------------------- % Scale both clean speech and processed speech to have same dynamic % range. Also remove DC component from each signal % ----------------------------------------------------------------------
%clean_speech = clean_speech - mean(clean_speech); %processed_speech = processed_speech - mean(processed_speech);
%processed_speech = processed_speech.*(max(abs(clean_speech))/ max(abs(processed_speech)));
overall_snr = 10* log10( sum(Speech.^2)/sum((Speech-Enhanced_speech).^2));
% ---------------------------------------------------------------------- % Global Variables % ----------------------------------------------------------------------
% sample_rate = 8000; % default sample rate % winlength = 240; % window length in samples % skiprate = 60; % window skip in samples winlength = fix(30*sample_rate/1000); %240; % window length in samples skiprate = floor(winlength/4); % window skip in samples MIN_SNR = -10; % minimum SNR in dB MAX_SNR = 35; % maximum SNR in dB
% ---------------------------------------------------------------------- % For each frame of input speech, calculate the Segmental SNR % ----------------------------------------------------------------------
num_frames = clean_length/skiprate-(winlength/skiprate); % number of frames start = 1; % starting sample window = 0.5*(1 - cos(2*pi*(1:winlength)'/(winlength+1)));
for frame_count = 1: num_frames segmental_snr = zeros(1,num_frames); % ---------------------------------------------------------- % (1) Get the Frames for the test and reference speech. % Multiply by Hanning Window. % ----------------------------------------------------------
clean_frame = Speech(start:start+winlength-1);
processed_frame = Enhanced_speech(start:start+winlength-1);
clean_frame = clean_frame.*window;
processed_frame = processed_frame.*window;
% ----------------------------------------------------------
% (2) Compute the Segmental SNR
% ----------------------------------------------------------
signal_energy = sum(clean_frame.^2);
noise_energy = sum((clean_frame-processed_frame).^2);
segmental_snr(frame_count) = 10*log10(signal_energy/(noise_energy+eps)+eps);
segmental_snr(frame_count) = max(segmental_snr(frame_count),MIN_SNR);
segmental_snr(frame_count) = min(segmental_snr(frame_count),MAX_SNR);
start = start + skiprate;
segSNR= mean( segmental_snr);
end
and I receive this message: Output argument 'segmental_snr' is not assigned on some execution paths. how can I tackle this? Thanks in advance

Categorie

Scopri di più su Modeling in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by