knn grouping matrix representation

I am new to using KNN and was told that use grouping matruix in the following format for example,
G=[1;1;1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;;3;3;3;3;3;3;3;3;4;4;4;4;4;4;4;4]
surly, supposed i have 500 trainig sample data, woukd i have to put in G 500 numbers and so on? this is not scalable? there must a shorter way of representing G. Thanks you

Answers (1)

G = [repmat(1, 1, number_in_first_group), repmat(2, 1, number_in_second_group), repmat(3, 1, number_in_third_group)]
Or
G = [ones(1, number_in_first_group), 2 * ones(1, number_in_second_group), 3 * ones(1, number_in_third_group)]
or
G = repelems([1, 2, 3], [number_in_first_group, number_in_second_group, number_in_third_group])

Asked:

on 3 May 2017

Answered:

on 4 May 2017

Community Treasure Hunt

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

Start Hunting!