필터 지우기
필터 지우기

index exceed matrix elements

조회 수: 1 (최근 30일)
Tasneem Abed
Tasneem Abed 2023년 7월 11일
댓글: Voss 2023년 8월 15일
i want data=[9 15 3000;
15 18 1800];to replace the one below
% data=[0 6 900;
% 6 7 2400;
% 7 15 3000;
% 15 18 1800;
% 18 22 3000;
% 22 24 1800];
data=[9 15 3000;
15 18 1800];
power=data(:, 3)
power = 2×1
3000 1800
Dt=data(:,2) - data(:,1)
Dt = 2×1
6 3
Power_Generated=power.*Dt
Power_Generated = 2×1
18000 5400
Total_power1=sum(Power_Generated)
Total_power1 = 23400
Total_power2=power.*Dt;
DATA=[data(:,1) data(:,2) power];
Average_load=Total_power2/sum(Dt);
peak_load=max(power);
Daily_LF=Average_load/peak_load*100;
Results=[Average_load peak_load*ones(size(Daily_LF)) Daily_LF];
L=length(data);
timeinterval=data(:,1:2) ;
t = sort(reshape(timeinterval,1,2*L));
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
for n = 1:L
P(2*n-1) = power(n);
P(2*n) = power(n);
end
subplot(2,1,1)
plot(t,P,'b')
xlabel(['Timer, Hr'])
ylabel(['Power, W'])
title('consumed Power, W versus time, hour')
xlim([0 24])
grid on
grid minor

답변 (2개)

Voss
Voss 2023년 7월 11일
Replace this:
L=length(data);
with this:
L=size(data,1);
length(data) gives the size of the longest dimension of data, which is 6 when data is 6-by-3 but is 3 when data is 2-by-3. What you really want is the size of the first dimension, i.e., the number of rows of data, so use size(data,1).
  댓글 수: 1
Voss
Voss 2023년 8월 15일
@Tasneem Abed: Did this answer work for you?

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


Mathieu NOE
Mathieu NOE 2023년 7월 11일
Code improved below
same mistake found as @Voss
% data=[0 6 900;
% 6 7 2400;
% 7 15 3000;
% 15 18 1800;
% 18 22 3000;
% 22 24 1800];
data=[9 15 3000;
15 18 1800];
power=data(:, 3);
Dt=data(:,2) - data(:,1);
Power_Generated=power.*Dt;
Total_power1=sum(Power_Generated);
% Total_power2=power.*Dt; % same as 2 lines above : Power_Generated=power.*Dt;
% DATA=[data(:,1) data(:,2) power]; % what for ? this is exactly the same
% as array "data" at the beginning of your code
% Average_load=Total_power2/sum(Dt);
Average_load=Power_Generated/sum(Dt);
peak_load=max(power);
Daily_LF=Average_load/peak_load*100;
Results=[Average_load peak_load*ones(size(Daily_LF)) Daily_LF];
L=size(data,1); % get number of rows
timeinterval=data(:,1:2) ;
t = sort(reshape(timeinterval,1,2*L)); % this works
% t = sort(timeinterval(:)); % this works too ! (and is simpler to write)
for n = 1:L
P(2*n-1) = power(n);
P(2*n) = power(n);
end
subplot(2,1,1)
plot(t,P,'b')
xlabel(['Timer, Hr'])
ylabel(['Power, W'])
title('consumed Power, W versus time, hour')
xlim([0 24])
grid on
grid minor

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by