I also want to to be able to separate the dataset for training and testing purpose. And then later combine both the datasets into one for further use.

I guess we can use the index values for this one.

3 views (last 30 days)

Show older comments

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

Khushboo
on 31 Oct 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.

Rajeev
on 31 Oct 2022

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)

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

Start Hunting!