MATLAB: Histogram(​’BinEdges’​,edges , ‘BinCounts’, counts) throws “Index exceeds matrix dimensions.” error

index exceeds matrix dimensions

I have the following code:
edges = SteppingRealTimesSec(:,1);
counts = SteppingRealTimesSec(:,3);
histogram('BinEdges',edges , 'BinCounts', counts)
This throws the error "Index exceeds matrix dimensions.". Even when substituting the following for edges and counts:
edges = [ 1 2 3 4 5 6];
counts = [ 2 4 2 6 4];
Note that MATLAB states "For numeric histograms, the number of bins is length(edges)-1."
I have no idea why I keep receiving this error for such a simple case, can someone please help?

Best Answer

This works fine for me:
edges = [ 1 2 3 4 5 6];
counts = [ 2 4 2 6 4];
histogram('BinEdges',edges , 'BinCounts', counts)
Note that when you do
edges = SteppingRealTimesSec(:,1);
counts = SteppingRealTimesSec(:,3);
edges and counts will both have the same number of elements. edges will NOT have one more element than counts because each vector is just a column from the SteppingRealTimesSec matrix, so each has the same number of elements which is the number of rows in SteppingRealTimesSec.