Output argument 'PreCharge' is not assigned on some execution paths
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
dpb
2013 年 7 月 22 日
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...
採用された回答
その他の回答 (1 件)
Heawa Mehmandoust
2017 年 10 月 24 日
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
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!