Hi Abdirizaak,
I understand that you want to extract random samples from your collected data and you want to ensure that the corresponding target data remains consistent with input data.
Follow the following steps to achieve the same:
- Combine your input data and target data into a cell array. This way, when you sample from the input data, the target data will automatically remain aligned. For example:
combined_data = [input_data, target_data];
- Use random sampling to select a subset of the combined data. This will ensure that both the input and target data are sampled together, maintaining consistency.
random_indices = randperm(size(combined_data, 1), num_samples);
sampled_data = combined_data(random_indices, :);
- After sampling, separate the input and target data back into their respective variables.
sampled_input_data = sampled_data(:, 1:end-1);
sampled_target_data = sampled_data(:, end);
By following these steps, you can randomly sample your input data while keeping the target data consistent.
To know more about “randperm” function used for sampling, checkout the following MathWorks Documentation link: