multiple CASE statements on interval within nested functions

后端 未结 2 1405
情歌与酒
情歌与酒 2021-01-15 01:13

Although I have come up with a work-around using multiple if / else if statements, I am curious in knowing what looks wrong with my case statement

2条回答
  •  甜味超标
    2021-01-15 02:10

    Building upon Suever's answer, and considering that you're actually trying to solve a data-binning problem, if you have R2015a or later, you can also use the built-in discretize function to achieve the same thing; e.g.:

    function bucket = ri(ar_vo,edgz)
      if nargin < 1
        edgz = [0, 0.005, 0.02, 0.05, 0.1, 0.15, 0.25, inf];
      end
      bucket = discretize(ar_vo,edgz);
      if isnan(bucket)
          error('MATLAB:RI Bucket:NotAvailable.');
      end
    end
    

提交回复
热议问题