我只是提供一些令我头疼的MATLAB代码。
function [hm,sm] = SKSClab(filename,data_type,maxk,true_labels,plot_flag)
%Inputs:
% filename: .txt file (or .jpg for images) with the data (instances as rows, features as columns)
% data_type:
% 1) net_unw = unweighted network (filename represents the adjacency list)
% 2) net_w = weighted network (filename represents the adjacency list)
% 3) vector = generic data points
% 4) ts = time-series
% 5) img = image
% maxk: maximum number of clusters to look for
% true_labels: labels if present
% plot_flag: 1 -> plot results, 0-> do not plot anything
然后
switch data_type
case 'vector'
THR_dim = 100;
if(size(X,2)<THR_dim)
kernel_type = 'RBF_kernel';
else
kernel_type = 'cosine_kernel'; %use cosine kernel when enough features are present
end
case 'ts'
kernel_type = 'corrrbf_kernel';
case 'net_w'
kernel_type = 'cosine_kernel';
case 'net_unw'
kernel_type = 'cosine_kernel';
case 'img'
kernel_type = 'chisquared_kernel';
end
%Tuning
tunestruct = {samplefunc,numreps,data_type,MS_criterion};
[Xtrain,optk,optsig2,tuningExtras] = tuneSKSC(data,kernel_type,maxk,tunestruct);
当我调用这样的代码时
SKSClab('proba',3,6,1)
我得到了
Loading data...
Undefined function or variable "kernel_type".
Error in SKSClab (line 179)
[Xtrain,optk,optsig2,tuningExtras] = tuneSKSC(data,kernel_type,maxk,tunestruct);
还有其他功能如此定义
function [Xtrain,optk,optsig2,extras] = tuneSKSC(datastruct,kernel,maxk,tunestruct)
问题是什么?我应该定义kernel_type
吗?我对MATLAB没有太多的经验。
答案 0 :(得分:2)
问题是,只有当kernel_type
参数是字符串data_type
,'vector'
,'ts'
,{{1}之一时,才会定义'new_w'
}和'new_unw'
。但是你传递的参数'img'
与任何这些情况都不匹配,所以3
未定义,因为没有赋值。
要解决此问题,请在kernel_type
语句中添加switch
分支:
otherwise
另一种方法是传递正确的参数:
switch data_type
case 'vector'
THR_dim = 100;
if(size(X,2)<THR_dim)
kernel_type = 'RBF_kernel';
else
kernel_type = 'cosine_kernel';
end
case 'ts'
kernel_type = 'corrrbf_kernel';
case 'net_w'
kernel_type = 'cosine_kernel';
case 'net_unw'
kernel_type = 'cosine_kernel';
case 'img'
kernel_type = 'chisquared_kernel';
otherwise
kernel_type = 'some_default_kernel_that_makes_sense';
end;
答案 1 :(得分:0)
我认为它可能有两个原因之一: 1)matlab中已经有一个名为kernel_type的函数 2)你没有定义kernel_type,你应该只输入kerneltype =“”;声明一个空字符串