Index exceeds the number of array elements (1).

조회 수: 1 (최근 30일)
Ahmed Abdulmunem
Ahmed Abdulmunem 2021년 1월 18일
편집: Cris LaPierre 2021년 1월 25일
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