# Index in position 1 exceeds array bounds (must not exceed 1)

조회 수: 1(최근 30일)
Jem Jem 2022년 12월 6일
댓글: DGM 2022년 12월 6일
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')
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')
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')
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')
title('H4')
hold off

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

### 답변(2개)

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표시숨기기 이전 댓글 수: -1

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

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표시숨기기 이전 댓글 수: 1
DGM 2022년 12월 6일
You mean like this? I don't know why it'd be a linear ramp either.
T = 24; % hour
H = 4; %house
PV = linspace(0,73,T); %PV output power/House
L = [75; 42; 68; 153];%Load Demand power/House
PV = repmat(PV,[H 1])
PV = 4×24
0 3.1739 6.3478 9.5217 12.6957 15.8696 19.0435 22.2174 25.3913 28.5652 31.7391 34.9130 38.0870 41.2609 44.4348 47.6087 50.7826 53.9565 57.1304 60.3043 63.4783 66.6522 69.8261 73.0000 0 3.1739 6.3478 9.5217 12.6957 15.8696 19.0435 22.2174 25.3913 28.5652 31.7391 34.9130 38.0870 41.2609 44.4348 47.6087 50.7826 53.9565 57.1304 60.3043 63.4783 66.6522 69.8261 73.0000 0 3.1739 6.3478 9.5217 12.6957 15.8696 19.0435 22.2174 25.3913 28.5652 31.7391 34.9130 38.0870 41.2609 44.4348 47.6087 50.7826 53.9565 57.1304 60.3043 63.4783 66.6522 69.8261 73.0000 0 3.1739 6.3478 9.5217 12.6957 15.8696 19.0435 22.2174 25.3913 28.5652 31.7391 34.9130 38.0870 41.2609 44.4348 47.6087 50.7826 53.9565 57.1304 60.3043 63.4783 66.6522 69.8261 73.0000
L = repmat(L,[1 T])
L = 4×24
75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153

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

### 범주

Find more on Matrices and Arrays in Help Center and File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by