Note that there are some explanatory texts on larger screens.

plurals
  1. POMatlab: Unused part of a Switch slowing down M-file script
    primarykey
    data
    text
    <p>I am new to Matlab and programming in general, but I am curious about what I have noticed in a particular script I have made. I have a 'Switch' in a fairly complicated for loop that runs many times. When testing it on a file that uses only cases 0-4, I noticed that if I delete the switch cases 5-8 (no other changes) my time goes from 18.2 to 4.5 seconds. Was I wrong to think that cases are skipped and would not noticably affect the timing if they went unused?</p> <p>PS I am a rookie at all this so it may be user error, but I tried to check over everything to make sure it was not</p> <p>EDIT</p> <p>Okay so thanks for the help so far. The profiler thing was very cool, but I dont think it helped me figure out what is wrong yet. The thing that was slowing down the code the most was one particular 'if' statement that actually contains the switch. It was called 3,169,449 times in each case, but took 1.22 seconds without cases 5-8 and 15 seconds with. The code is very long, but I will post a simplified version with out the actaul operations of the cases. What the profiler did tell me is that cases 5-8 were never called, and it was not that they were complex functions, each case corresponds to the actual number 0-8 as its trigger value.</p> <pre><code> for x= 1:length(firstinSeq) for y= 1:length(littledataPassed-1) if firstinSeq(x,1)== littledataPassed(y,1) &amp;&amp; firstinSeq(x,2)== littledataPassed(y,2) %times and flight are the same switch firstinSeq(x,3) case 0 case 1 case 2 case 3 case 4 end end end end </code></pre> <p>Again, the part tof the script that struggles with all 9 cases is the if statement right before the switch.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload