MATLAB: Creating M histograms from an NxM table on separate plots

for loophistogramMATLAB

Hi there,
I have an N x M table and I am trying to create M histograms on different plots, I can't seem to figure out how to plot them on different figures. If I hold on, they all plot on the same axis'
data = readtable('file.csv'); % Import in wine raw data
predictors = data(:,1:width(data)-1); % remove quality as it is our output
headers = predictors.Properties.VariableNames; % Get predictor labels
%% Lets check to see how our predictors are distributed
statarray = grpstats(predictors,[],{'mean','std'})
for k = width(headers);
a = table2array(predictors(:,k)); % Converting from table to array for hist
histogram(a)
title(headers(1,k))
end
I'm also not sure why I can't pass a table row to a histogram and need to table2array the data.
Any help would be greatly appreciated. Thank you

Best Answer

A = 2*randn(1e4, 6) + 5*(0:5);
T = array2table(A);
for k = 1:width(T)
subplot(2, 3, k)
histogram(T{:, k})
end
Note that each histogram is roughly centered around a different multiple of five, but each has (roughly) the same shape.
Related Question