Calling function in the same script to plot graph

3 views (last 30 days)
I have this function
function z=Fun(u)
d=length(u);
a1=1000
b1= 16.19
c1=0.00048
a2=700
b2=16.6
c2=0.002
a3=680
b3=16.5
c3=0.00211
a4=370
b4=22.26
c4=0.0072
a5=660
b5=25.92
c5=0.00413
p1max=455
p2max=130
p3max=130
p4max=80
p5max=55
pd=480
p1=u(1)
p2=0
p3=0
p4=0
p5=pd-p1
z=a1 + (b1*p1) + c1*(p1)^2 + a5 + (b5*p5) + c5*(p5)^2 +60
I would like to call the z value in another function to plot graph z vs iteration
plot(N_iter,z); %N_iter is the number of iteration
xlabel('Iteration');
ylabel('Cost');

Accepted Answer

Cris LaPierre
Cris LaPierre on 29 Dec 2020
You would need to first call the function and capture its output in a variable named z.
in = ???;
z = Fun(in);
plot(N_iter,z); %N_iter is the number of iteration
xlabel('Iteration');
ylabel('Cost');
Learn more about functions here.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots 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!