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!