MATLAB: Simulation results on command window

command

How do I display the average for the outputs of SNR, SNRM and SNRP on the command window or workspace?
It keeps showing me 3 numbers like this.
function [ SNR, SNRM, SNRP ] = SNRmulfication( Ip,Is,Nrep,M)
%SNR=SN ratio after multification
%SNM=SN ratio after signal mutification
%SNRP=SN after power multification
%This code simulates the signal to noise multification
%This is without a multification factor
SD=sqrt(Ip); %Standard deviation of power.
for i=1:Nrep
Inp=randn(1,Nrep)*SD+Ip; %Initial power fluctuation

S=0.1*Inp; %Power to Signal conversion


SD1=sqrt(S); %Standard deviation of signal

Res=randn(1,1)*SD1+S; %Detected Signal

Signal=mean(Res); %Mean Detected Signal

Noise=std(Res); %Noise


SNR(i)=Signal/Noise %Signal to noise ratio without multification
end
%This multiply the signal after detection
for i=1:Nrep
Inp=randn(1,Nrep)*SD+Ip; %Initial power fluctuation
S1=0.1*Inp; %Power to Signal conversion
SD1=sqrt(S1);%Standard deviation of signal
Res1=randn(1,1)*SD1+S1; %Detected Signal
Rep=Res1*M; %Detected Signal after multification
SD11=sqrt(Rep);
Rep1=Rep+randn(1,1)*SD11+Rep; %Signal fluctuation after multification
Signal1=mean(Rep1); %Mean Detected Signal
Noise1=std(Rep1); %Noise
SNRM(i)=Signal1/Noise1 %Signal to noise
end
%This multiflies the initial power
Ip1=Ip*M; %Power after multification
SD2=sqrt(Ip1); %Standard deviation of multificated power
for i=1:Nrep
Inp2=randn(1,Nrep)*SD2+Ip1; %power fluctuation
S2=0.1*Inp2; %Power to Signal conversion
SD3=sqrt(S2); %Standard deviation of the signal
Res2=randn(1,1)*SD3+S2; %Detected signal fluctuation
Signal2=mean(Res2); %Mean signal
Noise2=std(Res2); %Noise
SNRP(i)=Signal2/Noise2 %Signal to noise ratio after power multification
end
end
%Copy this to command window to simulate "SNRmulfication(1000,100,3,100);"

Best Answer

What you can do is calculate the average outside of the loop, for example, for snrm:
for i=1:Nrep
Inp=randn(1,Nrep)*SD+Ip; %Initial power fluctuation
S1=0.1*Inp; %Power to Signal conversion
SD1=sqrt(S1);%Standard deviation of signal
Res1=randn(1,1)*SD1+S1; %Detected Signal
Rep=Res1*M; %Detected Signal after multification
SD11=sqrt(Rep);
Rep1=Rep+randn(1,1)*SD11+Rep; %Signal fluctuation after multification
Signal1=mean(Rep1); %Mean Detected Signal
Noise1=std(Rep1); %Noise
SNRM(i)=Signal1/Noise1; %Signal to noise
end
avg_SNRM = mean(SNRM)
%next for looop
note: dont forget to add ';' to suppress the output of each iteration