Hi, I want to know which looping is better from programming point of view i.e. for loop or switch.
In my coding I have used switch and case , and it is taking lots of time. I am using it for optimization.
Kindly help me out in order to improve the speed of my code.
Any suggestion is appreciated.
Thanks, Suraj

댓글 수: 1

Stephen23
Stephen23 2015년 4월 9일
편집: Stephen23 2015년 4월 9일
Considering one single switch or loop in isolation might not be the best way to optimize code. Upload your whole Mfile and we can see at it in context! There might be other improvements and simplifications that you have not considered, that make the switch/loop irrelevant or insignificant.

댓글을 달려면 로그인하십시오.

 채택된 답변

Thomas Koelen
Thomas Koelen 2015년 4월 9일

0 개 추천

read in the comments. (I guess you are talking about if statements and not loops)

댓글 수: 4

Suraj Srivastava
Suraj Srivastava 2015년 4월 9일
Hi Thomas,
Thanks for the reply.
I simply want to know which one is betetr......switch or if-statements.
Thomas Koelen
Thomas Koelen 2015년 4월 9일
편집: Thomas Koelen 2015년 4월 9일
That depends on how many iterations you are planning to do! You should just try it out yourself with tic and toc, but I don't think the time you are going to win is more than the time youll spend on testing!
Suraj Srivastava
Suraj Srivastava 2015년 4월 9일
suppose I am using it in Optimization process and there is around 10000 iterations.
Thomas Koelen
Thomas Koelen 2015년 4월 9일
I'm gonna go with switch in this case.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by