Extracting testing and training data from a single dataset
Ältere Kommentare anzeigen
I have a dataset of size 14400 x 14, where the first 2 columns represent a users x- and y- position, and ranges from 1 : 121.
Example:
first_col second_col . . . . . .
1 1
1 2
1 3
so on to 121
2 1
2 2
so on to 121
3 so on to 121
. .
so on to 121 so on to 121
I want to separate the testing data based on the user location ranging from first_col(1:30) and 2nd column(1:30).
I a using for loop, but it is taking a lot of time.
I would really appreciate any kind of suggestions on this issue.
Thank You
2 Kommentare
Rahul Gulia
am 28 Okt. 2022
Bearbeitet: Rahul Gulia
am 28 Okt. 2022
Khushboo
am 31 Okt. 2022
Hi Rahul,
I am sorry I did not fully understand how you want your test data to look like. Could you kindly elaborate more using an example? From what I assume, using slicing would work for your use case.
Akzeptierte Antwort
Weitere Antworten (2)
Rajeev
am 31 Okt. 2022
0 Stimmen
Hi Rahul,
Logical Indexing can be used to extract the required data from the array.
Assuming that the name of the matrix is "location", to extract only the user locations ranging from 1 to 30, one can proceed in the following way:
% logical indexing is used to extract the index of the required data from each column
first_col_index = first_col <= 130;
second_col_index = second_col <=130;
% logical & (and) operations gives the index of columns where both coordinates are less than or equal to 130
location_index = first_col_index & second_col_index;
% assuming the matrix "location" is a row matrix, the logical index array can be used to extract the required data
location_new = location(location_index,:);
Here is the documentation for logical indexing: Matrix Indexing in MATLAB - MATLAB & Simulink (mathworks.com)
Rahul Gulia
am 31 Okt. 2022
0 Stimmen
Kategorien
Mehr zu Pattern Recognition finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
