MATLAB中switch结构实现

2025-05-09 10:09:21
推荐回答(1个)
回答1:

和C语言中基本相同,只是每个case之后不用加break;

假设
method = 'Bilinear';

执行下面判断
switch lower(method)
case {'linear','bilinear'}
disp('Method is linear')
case 'cubic'
disp('Method is cubic')
case 'nearest'
disp('Method is nearest')
otherwise
disp('Unknown method.')
end

输出:
Method is linear