if i have two function first
function [label,s] = LSC(data,k,opts) % Set and parse parameters
if (~exist('opts','var')) opts = [];end***%[how to define variables p and r to take values from loop]***
maxIter = 100; numRep = 10; mode = 'kmeans'; nSmp=size(data,1); % Landmark selection
if strcmp(mode,'kmeans') kmMaxIter = 5; if isfield(opts,'kmMaxIter') kmMaxIter = opts.kmMaxIter; end kmNumRep = 1; if isfield(opts,'kmNumRep') kmNumRep = opts.kmNumRep; end [dump,marks]=litekmeans(data,p,'MaxIter',kmMaxIter,'Replicates',kmNumRep); [label,s] = kmedo(U',k);end
second function
function Accuracy=yarbb(data,x)%for i=1:100
rng('default')n = size(data,1);data_rand = data(randperm(n),:);m = ceil(n/10);k = 1:m:n-m;test = data_rand(k:k+m-1,:);train = [data_rand(1:k-1,:); data_rand(k+m:end,:)];adj=ed(train,data);for i=1:100rng('default')***for p=3:5 for r=2:5 [p,r][cluster_labels,s] = LSC(adj,x);***auc= (ndash + 0.5 * nddash)/(ndash+nddash+nn);endAccuracy = mean(auc)endend
in second function i used for loop to pass variables "p" and "r" to first function to calculate "s" and return again to second function , but when i used for loop for variables "p" and "r" this caused errors that are [undefined variables "p" and adj(0,0) not found).
Best Answer