How to plot smooth graph?

조회 수: 2 (최근 30일)
Ain Athirah
Ain Athirah 2018년 11월 1일
댓글: Ain Athirah 2018년 11월 1일
Hi, I was stuck here.. can someone help me out? How do I make the Pbat1 and Pbat2 smooth?
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
plot(P_load,'linewidth', 2)
P_gen = ones(1,24).*29000; % Watts
P_lowerlimit = ones(1,24).*10000; % Watts
hold on
plot(P_gen, 'linewidth', 2)
plot(P_lowerlimit, 'linewidth', 2)
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
plot(Pbat1, 'linewidth', 3)
plot(Pbat2, 'linewidth', 3)
legend('Load','Generator','Lower limit','Battery energy(Discharge)','Battery energy(Charge)')
If possible, i need with spline code. Help appreciated, thank you.

채택된 답변

madhan ravi
madhan ravi 2018년 11월 1일
편집: madhan ravi 2018년 11월 1일
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,'pchip')
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,'og',xx,yy,'-m','linewidth', 2)
xx=linspace(1,numel(x),1000)
yy=interp1(x,P_lowerlimit,xx,'spline')
plot(x,P_lowerlimit,'or',xx,yy,'-b','linewidth', 2)
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,'ok',xx,yy,'-y','linewidth', 3)
xx=linspace(1,numel(x),1000)
yy=interp1(x,Pbat2,xx,'spline')
plot(x,Pbat2,'oc',xx,yy,'-r','linewidth', 3)
legend('Load','Generator','Lower limit','Battery energy(Discharge)','Battery energy(Charge)')
  댓글 수: 14
madhan ravi
madhan ravi 2018년 11월 1일
Please ask a separate question
Ain Athirah
Ain Athirah 2018년 11월 1일
okay

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by