which one is faster for loop or switch

6 Ansichten (letzte 30 Tage)
Suraj Srivastava
Suraj Srivastava am 9 Apr. 2015
Kommentiert: Thomas Koelen am 9 Apr. 2015
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 Kommentar
Stephen23
Stephen23 am 9 Apr. 2015
Bearbeitet: Stephen23 am 9 Apr. 2015
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Thomas Koelen
Thomas Koelen am 9 Apr. 2015
read in the comments. (I guess you are talking about if statements and not loops)
  4 Kommentare
Suraj Srivastava
Suraj Srivastava am 9 Apr. 2015
suppose I am using it in Optimization process and there is around 10000 iterations.
Thomas Koelen
Thomas Koelen am 9 Apr. 2015
I'm gonna go with switch in this case.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by