How to display output in a loop?

17 views (last 30 days)
Brandon Fricke
Brandon Fricke on 5 Nov 2019
Answered: Subhadeep Koley on 8 Nov 2019
Hello,
I am doing this function . I cannot figure out how to display my output in how it is required. I have tried 'display' and fprintf. The code is correct(hopefully) becuase they gave us a flow diagram with what the code should be. I can attach later but i dont know how to get the display function to work in the loop and output in this format. I also need to add a plot of efficiency vs load.
output format.png
%Declare Variables and Values
kVA=10000
Vp = 10
f = 60
Psc=204
Poc=133
Vsc=95
Isc=4.54
pf = -0.85
%Calculate rated Current
IR=kVA/Vp
%Calculate REQp
REQp=Psc/Isc^2
%Load Matrix is in percentage
NSTEP = [120:-5:0]
if NSTEP>=0
%
%Calculate total losses
Ploss=Psc + Poc
%Obtain Input PowerCalculate Pout
Pout=kVA*(NSTEP/(100*pf))
%Calculate PSC @ each load
Pscl=Psc.*((NSTEP/100).^2)
Pin = Ploss + Pout
%Calculate efficiency
n = (Pout/Pin)*100
fprintf (Pout,Pin,Ploss,Pscl,Poc,n)
else
%Calculate for Maximum efficiency
I = sqrt(Poc/REQp)
%Calculate maximum efficiency
nmax = ((Vp*I*pf*100)/(Vp*I*pf+Poc+Psc))
%display max efficiency
display('nmax')
end

Answers (1)

Subhadeep Koley
Subhadeep Koley on 8 Nov 2019
Hi, you can use the function disp() to display the variables in the command window. Also, I have made some changes in your code. Refer to the below code to see whether it is giving the expected output.
clear; clc;
% Declare Variables and Values
kVA = 10000;
Vp = 10;
f = 60;
Psc = 204;
Poc = 133;
Vsc = 95;
Isc = 4.54;
pf = -0.85;
% Calculate rated Current
IR = kVA/Vp;
% Calculate REQp
REQp = Psc/(Isc^2);
% Load Matrix is in percentage
NSTEP = 120:-5:0;
% Indexing variable
% i = 1;
for i=1:1:numel(NSTEP)
% Calculate total losses
Ploss(i) = Psc + Poc;
% Obtain Input PowerCalculate Pout
Pout(i) = kVA*(NSTEP(i)/(100*pf));
% Calculate PSC @ each load
Pscl(i) = Psc.*((NSTEP(i)/100).^2);
Pin(i) = Ploss(i) + Pout(i);
% Calculate efficiency
n(i) = (Pout/Pin)*100;
end
Poc_disp(1:25)=Poc;
% Store every variable inside a table
T = table(NSTEP',Pout',Pin',Ploss',Pscl',Poc_disp',n','VariableNames',{'LOAD','P_out','P_in','P_loss','P_scl','P_oc','efficiency'});
% Calculate for Maximum efficiency
I = sqrt(Poc/REQp);
% Calculate maximum efficiency
nmax = ((Vp*I*pf*100)/(Vp*I*pf+Poc+Psc));
% Display values
disp('OUTPUT'); disp(T);
disp(['Maximum Efficiency = ',num2str(nmax)]);
Hope this helps!

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!