The following function is generating an error.
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
Usage
>> [errindep errdep errparzen] = select_red(train, test)
errindep =
0.1089181 0.0029240 0.2309942
error: element number 2 undefined in return list
Can you tell why is it generating an error message?
You are asking too much from the poor function. You want three outputs and it can only deliver one (which is a vector containing three numbers).
If you want the function to produce the three numbers as separate outputs, declare it as
[ercf_indep, ercf_dep, ercf_parzen] = select_red(train, test)
and remove the line retval = ...
at the end.
If you don't want to modify the function, you need to call it with one output:
out = select_red(train, test);
Then unpack that output into three numbers:
ercf_indep_out = out(1) ercf_dep = out(2); ercf_parzen = out(3);
Or the unpacking can be done using a comma-separated list generated from a cell array:
out_cell = num2cell(out); [ercf_indep_out, ercf_dep, ercf_parzen] = out_cell{:}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.