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.
댓글 수: 0
답변 (1개)
Cris LaPierre
2021년 1월 18일
댓글 수: 2
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)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!