【发布时间】:2019-12-11 17:05:40
【问题描述】:
我试图从我的函数中返回 for 循环的所有值,并且我需要在函数之外调用它们。但我只得到 for 循环的最后一行,我还需要 for 循环的先前结果。 这是我的代码
i=input('Enter a start row: ');
j=input('Enter a end row: ');
c=input('Enter classifier variable column number:')
search= importfiledataset('search-queries-features.csv',i,j);
[n,p]=size(search);
if j>n
disp('Please enter a smaller number!');
end
[D1,Eps1]=findD(i,j,c,search);
disp(D1);
disp(n1);
function [D1,Eps1] = findD(i,j,c,search) %Find D vlaues with for loop for each classification value
for numOfClassifier = 1 : 100
a = search(search(:,c)==numOfClassifier,:) ;
q1 = a(all(~isnan(a),2),:); % for nan - rows
D1 = a(:,all(~isnan(a))) % for nan - columns WE FIND D1
n1=size(D1,1) %number of record belongs to classification
sampleSpace = size(search,1) %sample space of the priop probability(#of c1 + #of c2 .... cn)
pc1 = n1/sampleSpace %prior probability of the n
mu1 = mean(D1) %mean of D1
Z1 = D1 - mu1 % centered data of D1
Eps1 = (1/n1)*(transpose(Z1)*Z1) %covariance matrix if Z1
numOfClassifier = numOfClassifier + 1;
if search(:,c) ~= numOfClassifier
break
end
end
end
我要退货
- D1
- Eps1
我想返回 for 循环的全部值,但我只得到最后一行的值。
【问题讨论】:
-
如果有人为您提供了一个可行的答案,而不是回答“谢谢,它帮助了我”,要么赞成,要么接受答案。见What should I do when someone answers my question?
标签: matlab for-loop return return-value function-call