How to normalize the values of a dataset of 32X8X2X15000 in the range -0.5 to 0.5 using standard deviation

6 vues (au cours des 30 derniers jours)
If I have dataset of 4D single with size 32X8X2X15000. And I have calculated the mean and standard deviation of thart particular dataset. Now I want to bring all the values of the dataset within the range -0.5 to 0.5. How to do that

Réponses (1)

Udit06
Udit06 le 29 Août 2023
Hi Anusaya,
I understand that you are trying to scale your data present in the 4-D matrix so that it falls in the range [-0.5, 0.5]. You can try out the following two approaches to scale your data:
  1. Use the rescale function provided by MATLAB to scale the values between any given range [a,b]. You can read more about the “rescalefunction using the following MathWorks documentation link: https://www.mathworks.com/help/matlab/ref/rescale.html
  2. Otherwise, you can use the calculated mean and standard deviation to scale the values as shown below.
% Assuming your dataset is stored in a variable called 'data'
data = rand(32, 8, 2, 15000) % your 4D dataset with size 32x8x2x15000
% Calculate the mean and standard deviation
mu = mean(data(:));
sigma = std(data(:));
% Normalize the dataset within the range -0.5 to 0.5
normalized_data = (data - mu) / (2 * sigma);
normalized_data = normalized_data * 0.5;
% Clip values outside the range -0.5 to 0.5
normalized_data = max(min(normalized_data, 0.5), -0.5);
% Verify the range of the normalized data
min_val = min(normalized_data(:));
max_val = max(normalized_data(:));
disp(['Minimum value: ', num2str(min_val)]);
disp(['Maximum value: ', num2str(max_val)]);
I hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by