How to label smooth spline graph?
Show older comments
I have a new problem now on how to label them. by using legend code, seems it be different between points and line.. i use spline code. see the picture:

and here is my code:
P_load = [0,8000,10000,11000,20000,25000,25000,21000,30000,20000,12000,45000....
12000,45000,23300,12000,15000,17000,20000,16000,12200,1000,2000,100];% Watts
x = 1:numel(P_load)
xx = linspace(1,numel(x),1000)
yy = interp1(x,P_load,xx,'spline')
plot(x,P_load,'*g',xx,yy,'-k', 'linewidth', 2)
P_gen = ones(1,24).*29000; % Watts
P_lowerlimit = ones(1,24).*10000; % Watts
hold on
xx=linspace(1,numel(x),1000)
yy=interp1(x,P_gen,xx,'spline')
plot(x,P_gen,'--r',xx,yy,'--r')
xx=linspace(1,numel(x),1000)
yy=interp1(x,P_lowerlimit,xx,'spline')
plot(x,P_lowerlimit,'--m',xx,yy,'--m')
grid
xlim([1,24])
xlabel('Time (hours)')
ylabel('Power (Watts)')
hold on
Pnet1 = [];
Pbat1 = [];
Pnet2 = [];
Pbat2 = [];
for h = 1:24
Pnet1(h) = P_gen(h) - P_load(h);
Pnet2(h) = P_lowerlimit(h) - P_load(h);
if Pnet1(h) > 0
Pbat1(h) = 0;
else
Pbat1(h) = P_load(h) - P_gen(h);
end
if Pnet2(h) < 0
Pbat2(h) = 0;
else
Pbat2(h) = [P_gen(h) - P_load(h)]/3;
end
end
xx = linspace(1,numel(x),1000)
yy = interp1(x,Pbat1,xx,'spline')
plot(x,Pbat1,'-c',xx,yy,'-c','linewidth', 3)
xx = linspace(1,numel(x),1000)
yy = interp1(x,Pbat2,xx,'spline')
plot(x,Pbat2,xx,yy,'-b','linewidth', 3)
legend('Load','Generator','Lower limit','Battery energy(Discharge)','Battery energy(Charge)')
How to make them be one? as they need to be one. Thanks :D
Accepted Answer
More Answers (0)
Categories
Find more on Spline Postprocessing 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!