switch case efficiency question
Show older comments
I have a question about switch/case structure.
if true
switch input[a,b]
case [1,1]
do something 1
case [1,2]
do something 2
case ...
... etc.
end
since a =1 to 40 and b = 1 to 11. So i will end up with a few hundred cases. How to make the code doing the selection more efficient? Thanks, Chong
Accepted Answer
More Answers (2)
Chong Tao
on 14 Sep 2013
Jan
on 15 Sep 2013
Please post the problem in valid Matlab syntax. "switch input[a,b]" could mean a variety of different things.
Your code example seems to be a look-up-table. Then this would be more efficient:
a = 1;
b = 2;
lut = [18, 20, 23; 19, 26, 65];
M = lut(a, b);
2 Comments
Chong Tao
on 15 Sep 2013
Image Analyst
on 15 Sep 2013
I thought "Do something" meant executing a bunch of code that was all unique, not just assigning a single variable like M. If it's really as simple as assigning some variable, then a look up table would work. If they're integers you can use intlut() in the Image Processing Toolbox.
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!