Index exceeds the number of array elements (1).

1 次查看(过去 30 天)
Hi guys , how can i fix this
cost_benefit=[];
controller_cost=1;
k=4;
for i=1:k
cost_benefit(1,i)=(controller_cost*i)/(L_average(i));
end
%
k=[1 2 3 4];
figure;
AxesH = axes('Xlim', [1, 4], 'XTick', 1:1:4, 'NextPlot', 'add');
line(k,cost_benefit,'MarkerSize',20,'Marker','.','Color','b')
hold on
box on;
plot(k,cost_benefit, '-b')
set(gca,'fontsize',20)
% title('Optimal number of controllers based on cost benefit');
xlabel ('Number of controllers','FontSize',30, 'FontWeight','bold')
ylabel ('Cost benefit ($/ms)','FontSize',30,'FontWeight','bold')
where the error apears in this line
cost_benefit(1,i)=(controller_cost*i)/(L_average(i));
Thank you all.

回答(1 个)

Cris LaPierre
Cris LaPierre 2021-1-18
You can follow the steps provided in this answer to determine the issue.
  2 个评论
Ahmed Abdulmunem
Ahmed Abdulmunem 2021-1-25
I followed the answer you provided but i can not figure out how fix it
Cris LaPierre
Cris LaPierre 2021-1-25
编辑:Cris LaPierre 2021-1-25
Unfortunately, you haven't shared enough details if your post for us to help you, either.
Try using the steps I shared to inspect what is happening with L_average(i)
To get started, try running the following.
L_average(1)
L_average(2)
L_average(3)
L_average(4)
You may find the Array Indexing page helpful.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by