Have you ever wondered how to go about creating a simple pivot table in MATLAB? Well it is actually easier than you may think. All it takes is 4 lines of code.

Here is the code that appeared in the video above. The Excel file Patients.xlsx was created from the data in patients.mat which comes with MATLAB.

% import data
data = readtable('Patients.xlsx');

% split data based on rows and columns
[aGroup, Gender, Location] = findgroups(data.Gender, data.Location);

% apply mean function to Height for each group
avgHeight = splitapply(@mean, data.Height, aGroup);

% visualize what has been done
simplePivot = table(Gender, Location, avgHeight);

% create your simple pivot table
simplePivot = unstack(simplePivot, 'avgHeight', 'Location')

This is a short example of the Advance Service that VersionBay offers. If you would like VersionBay to look at your code just Contact Us.