how can I apply for loop to process a method 10 times and save different results for each time process runs for different variables.

3 ビュー (過去 30 日間)
How can I apply for loop to simulate a method 10 times and save different results for each time process runs for different variables. Suppose I have process command
ma1 = knnclassify(testsample1,trainingset,group),
testsample1 = mobile_Motorola
(total 10 types of mobile) training set and group will be same for each simulation. This command should run after knn command.
Ka1 = sum(ma1==samplevalue)/length(ma1);
With each simulation sample value should also add by 1 sample value=1 to 10.

採用された回答

Julia
Julia 2014 年 7 月 7 日
Assume the types are stored in matrix_types:
matrix_types
matrix_types(1)='type 1'
matrix_types(2)='type 2'
and so on and Ka1 should also be an array:
Ka1 = zeros(1,10);
for i = 1:10
ma1 = knnclassify(matrix_types(i),trainingset,group);
Ka1(i) = sum(ma1==samplevalue)/length(ma1);
end
So after the 10 iterations of the loop you find your results in Ka1.

その他の回答 (1 件)

Julia
Julia 2014 年 7 月 7 日
Is it possible to store your 10 types in an array/cell-array? Then you could use the index to call the right type in the for-loop.
  5 件のコメント
Zishan
Zishan 2014 年 7 月 8 日
I have done the same but there is some error like this. "??? In an assignment A(I) = B, the number of elements in B and I must be the same." I am attaching file, please have a look and tell me. First I am just using 'ma' and 'Ka' results and not including 'mb', 'mc', 'Kb', 'Kc' experiments. Regards.
Julia
Julia 2014 年 7 月 9 日
編集済み: Julia 2014 年 7 月 9 日
Try to determine the sizes of ma and Ka by using the zeros-matrix.
Your ma-matrix is unnecessarily big ... Compare what you did to that what I wrote.
You also have to comment the unused code out. Else this could also be a reason for errors.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by