write code that shuffles a dataset for training in matlab

Here's a code snippet that shuffles a dataset in Matlab for machine learning training:

main.m
% input dataset
dataset = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

% shuffle dataset
n = length(dataset);
idx = randperm(n);
shuffled_dataset = dataset(idx);

disp(shuffled_dataset);
176 chars
10 lines

Explanation:

  • randperm(n) generates a vector of random integers from 1 to n in a random order
  • The vector contains the indexes to rearrange the original dataset
  • dataset(idx) rearranges the dataset according to the shuffled indexes

You can modify this code to fit your own dataset and save it to a new variable for subsequent machine learning training purposes.

gistlibby LogSnag