error: element number 2 undefined in return list
<p>The following function is generating an error.</p>

<pre><code>function [retval] = select_red(train, test)
% shuffle test/data points
  shuffled_test = test(randperm(size(test, 1)), :);

  clubs     = shuffled_test(shuffled_test(:, 1) == 1, :);
  diamonds  = shuffled_test(shuffled_test(:, 1) == 2, :);
  hearts    = shuffled_test(shuffled_test(:, 1) == 3, :);
  spades    = shuffled_test(shuffled_test(:, 1) == 4, :);

  clubs = clubs(1: floor(size(clubs,1)/2),:);
  spades = spades(1: floor(size(spades,1)/2),:);

  shuffled_test = [clubs ; diamonds ; hearts ; spades];

  shuffled_test = shuffled_test(randperm(size(shuffled_test, 1)), :);

  ercf_indep = bayescls(train, shuffled_test, @pdfindep, 0.25 * ones(1,4), 0.1);
  ercf_dep = bayescls(train, shuffled_test, @pdfdep, 0.25 * ones(1,4), 0.1);
  ercf_parzen = bayescls(train, shuffled_test, @pdfparzen, 0.25 * ones(1,4), 0.1);

  retval = [ercf_indep   ercf_dep   ercf_parzen];
endfunction
</code></pre>

<p><strong>Usage</strong></p>

<pre><code>&gt;&gt; [errindep  errdep  errparzen] = select_red(train, test)
errindep =

    0.1089181   0.0029240   0.2309942

    error: element number 2 undefined in return list
</code></pre>

<p><strong>Can you tell why is it generating an error message?</strong></p>