MATLAB: Histogram Only Plotting 1 Point

histogramMATLAB

Hello,
I have a 1×100 table.
If I print 'error', it does the math, by taking the field 'constant' from each row of the table and subtracts by 94, and then prints all 100 results.
This is working correctly, but the plotting is not.
When I go to create the histogram of the 100 results, it only prints 1. Any idea why?
Thank you!

Best Answer

Don't use error as a variable name since it's a built-in function. Also, what is the badly-named "constant"? Is it an array or table? If it's a table, you need to extract the column and subtract 94 from it. Why are you using a loop when nothing inside the loop depends on the badly-named "i"?
This works just fine:
% Create sample data.
% column1 = rand(1000, 1);
column2 = rand(1000, 1);
t = table(column1, column2);
% Now that we have our data, let's get the histogram of one of the columns
theColumn = t{:, 2} - 94; % Extract column 2 and subtract 94
% Take the histogram of it
h = histogram(theColumn);
grid on;
xlabel('Value', 'FontSize', 20);
ylabel('Count', 'FontSize', 20);