在我的命令窗口中,我可以执行find([0 1 0])
,但是当我在函数中运行find时,如x = find([0 1 0])
,编译器告诉我find
未定义。为什么会这样?
错误是:
??? Error: File: frequentTuples.m Line: 12 Column: 21
"find" previously appeared to be used as a function or command, conflicting with its
use here as the name of a variable.
A possible cause of this error is that you forgot to initialize the
variable, or you have initialized it implicitly using load or eval.
这是代码。错误发生在for循环的第二行。
function [ tuples ] = frequentTuples( k, candidates, transactions, min_support )
%FREQUENTTUPLES Get frequent itemsets of size k
% Detailed explanation goes here
candidate_tuple_is_frequent = zeros(size(candidates, 1));
for i = 1:size(candidates, 1)
columns_of_candidate_items = transactions(:, candidates(i, :));
indices_of_transactions_containing_all_items = find(sum(columns_of_candidate_items') == k);
candidate_tuple_is_frequent(i) = size(indices_of_transactions_containing_all_items) >= min_support;
end
tuples = candidates(find(candidate_tuple_is_frequent, :));
end
答案 0 :(得分:5)
tuples = candidates(find(candidate_tuple_is_frequent, :));
什么时候应该
tuples = candidates(find(candidate_tuple_is_frequent), :);
您正在尝试调用find(candidate_tuple_is_frequent, :)
,它正在尝试将查找视为变量。这意味着在函数中查找的任何其他调用都会将其视为变量,因此就是错误。