how can I apply for loop to process a method 10 times and save different results for each time process runs for different variables.
Mostrar comentarios más antiguos
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.
1 comentario
Zishan
el 7 de Jul. de 2014
Respuesta aceptada
Más respuestas (1)
Julia
el 7 de Jul. de 2014
0 votos
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 comentarios
Zishan
el 7 de Jul. de 2014
I am not sure if I understand your code ...
You don't need to use my matrix_types, you already have your vector Testset. So instead of writing
testsample1=jh_mobile_Motorola_Milestone_a2;
write
testsample1=Testset(10);
To use a loop you only have to sort the entries in Testset in the right order.
for i =1:10
testsample1=Testset(i);
...
end
To store your results so you can view them afterwards you can use arrays or matrices.
Example with matrix ma:
ma(1,1)=knnclassify(testsample1,trainingset1,group);
ma(1,2)=knnclassify(testsample1,trainingset1,group,5);
ma(1,3)=knnclassify(testsample1,trainingset1,group,10);
ma(1,4)=knnclassify(testsample1,trainingset1,group,15);
ma(1,5)=knnclassify(testsample1,trainingset1,group,20);
ma(1,6)=knnclassify(testsample1,trainingset1,group,25);
ma(1,7)=knnclassify(testsample1,trainingset1,group,50);
And in a loop you replace the 1 with the counting variable. So each row contains a different test.
Zishan
el 8 de Jul. de 2014
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.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!