Index in position 1 exceeds array bounds (must not exceed 1)
조회 수: 1(최근 30일)
표시 이전 댓글
I need to run the following dada, but I facing this error "Index in position 1 exceeds array bounds (must not exceed 1)".
I used PV power output is same for each house, but different load demand for each house in 24 hour interval, and I tried to get that the (output power, load demand) versus (Time in 24 houre) for each H house. Any adea how to fix the error? Thank you in advance!
Remember, the PV out put is same for each House,
clear all
clc
close all
T = 24; % hour
H =4; %house
PV(:,1) = 73; %PV output power/House
L(:,1) = [75; 42; 68; 153];%Load Demand power/House
for t = 1:T
for h = 1:H
PV(h,t+1) = PV(h,t);
L(h,t+1) = L(h,t);
end
end
figure
subplot(4,1,1);
plot(0:23,PV(1,:),'-*b',0:23,L(1,:),'-*r','Linewidth',1);hold on
xlabel('Time in 24 houre')
ylabel('Power')
legend('PV Output', 'Load Demand')
title('H1')
subplot(4,1,2);
plot(0:23,PV(1,:),'-*b',0:23,L(2,:),'-*r','Linewidth',1);hold on
xlabel('Time in 24 houre')
ylabel('Power')
legend('PV Output', 'Load Demand')
title('H2')
subplot(4,1,3);
plot(0:23,P_PV(1,:),'-*b',0:23,L(3,:),'-*r','Linewidth',1);hold on
xlabel('Time in 24 houre')
ylabel('Power')
legend('PV Output', 'Load Demand')
title('H3')
subplot(4,1,4);
plot(0:23,P_PV(1,:),'-*b',0:23,L(4,:),'-*r','Linewidth',1);hold on
xlabel('Time in 24 houre')
ylabel('Power')
legend('PV Output', 'Load Demand')
title('H4')
hold off
댓글 수: 0
답변(2개)
Askic V
2022년 12월 6일
Here in the loop:
for t = 1:T
for h = 1:H
PV(h,t+1) = PV(h,t);
You're trying to access PV(2,1), when PV is PV = 73 73, so 1x2 in dimensions.
댓글 수: 0
DGM
2022년 12월 6일
It's unclear why you'd want to plot a bunch of constants, but this is apparently the same as what you're trying to do.
T = 24; % hour
H = 4; %house
PV = 73; %PV output power/House
L = [75; 42; 68; 153];%Load Demand power/House
PV = repmat(PV,[H T]);
L = repmat(L,[1 T]);
% ...
댓글 수: 2
참고 항목
범주
Find more on Matrices and Arrays 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!