Why does "mapstd" returns unexpected dimensions when I apply it to a new sample data?

R
rehmat_diya · Jul 9, 2021 · 2.2K views
Question
Why does "mapstd" returns unexpected dimensions when I apply it to a new sample data?   I have 4 sample data, each containing 2 predictor variables:   >> X = [ 2 1; 5 0; 3 0; 4 2]; I standardize this using "mapstd" as follow:   >> [Xnew, PS] = mapstd(X); However, when I try standardizing a single new sample data "Xtest", it produces a 4x2 array instead of 1x2 array: >> Xtest = [2 3]; >> XtestNew = mapstd('apply', Xtest, PS) XtestNew = 0.7071 2.1213 -0.1414 0.1414 0.2357 0.7071 -0.7071 0
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Aug 26, 2026
The "mapstd" function normalizes the input data row-wise (horizontally). Therefore, with your current implementation, you are actually normalizing each sample individually since you are putting your data one above the other in the following format (4 rows x 2 columns):
 
 
 
   X =
                [ sample1
                  sample2
                  sample3
                  sample4 ]

In order to use "mapstd" function to normalize each of your 2 predictor variables, you would need to store your data in the following format (2 row x 4 columns):

   X = [ sample1  sample2 sample3 sample4]
Then, you can use "mapstd" function and get 2 means and 2 standard deviations (one for each predictor variable).
 
 Making the necessary modification to the original data:
>> X = X';   % store sample column by column instead
>> [Xnew, PS] = mapstd(X);   
>> XtestNew = mapstd('apply', Xtest, PS);

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!