run the for loop only once Matlab
14 次查看(过去 30 天)
显示 更早的评论
Hi everybody, i want to know if its possible to run the for-loop only once.
total_Route = zeros(4,4);
for i=1:4
total_Route(i,1)=Distance_Traveled_CM;
total_Route(i,2)=Hauptantrieb_Verbrauchte_Energie_CM;
total_Route(i,3)=Nebenaggregate_Verbrauch_Real_CM;
total_Route(i,4)= i;
Total_Distance_Traveled_CM = sum(total_Route(:,1));
set(handles.edit3, 'string',Total_Distance_Traveled_CM);
Total_Hauptantrieb_Verbrauchte_Energie_CM=sum(total_Route(:,2));
set(handles.edit4, 'string',Total_Hauptantrieb_Verbrauchte_Energie_CM);
Total_Nebenaggregate_Verbrauch_Real_CM=sum(total_Route(:,3));
set(handles.edit5, 'string',Total_Nebenaggregate_Verbrauch_Real_CM);
%%Index
set(handles.edit15, 'string',i);
after the running this code, "i" is then at the end 4 and the for-loop will be runs 4 times
i want to run the for-loop only once and "i" should be incremented after each pass
I am thankful for every help
0 个评论
采纳的回答
Azzi Abdelmalek
2016-8-31
编辑:Azzi Abdelmalek
2016-8-31
If you want to run it once, then don't use a for loop, to increment ii, use
ii=mod(ii,4)+1
don't use i, it's used to represent complex numbers
8 个评论
更多回答(1 个)
Image Analyst
2016-8-31
Why not simply replace this line
for i=1:4
with this line:
i = 1;
It will do the code just once since it won't even be in a loop.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!