index exceed matrix elements
2 ビュー (過去 30 日間)
古いコメントを表示
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)
Dt=data(:,2) - data(:,1)
Power_Generated=power.*Dt
Total_power1=sum(Power_Generated)
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));
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
0 件のコメント
回答 (2 件)
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).
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!