Hi. 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?
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
EDIT
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.
for x= 1:length(firstinSeq)
for y= 1:length(littledataPassed-1)
if firstinSeq(x,1)== littledataPassed(y,1) && 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
Again, the part tof the script that struggles with all 9 cases is the if statement right before the switch.