Histogram Only Plotting 1 Point

조회 수: 8 (최근 30일)
Sclay748
Sclay748 2020년 8월 18일
댓글: Image Analyst 2020년 8월 19일
Hello,
I have a 1x100 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!

채택된 답변

Image Analyst
Image Analyst 2020년 8월 18일
편집: Image Analyst 2020년 8월 18일
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);
  댓글 수: 3
Sclay748
Sclay748 2020년 8월 18일
편집: Sclay748 2020년 8월 18일
I use a loop because it would only print one calulation out of 100 if I got rid of it.
Image Analyst
Image Analyst 2020년 8월 19일
Yeah but the badly-named error is not error(i) so the same error scalar is just getting overwritten every single time. After the loop you have only one single value, so you will have only one histogram bin. But like I said, if you have a table, you can extract the column all in one shot and can pass that to histogram() and not even use a loop at all.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Binbin Qi
Binbin Qi 2020년 8월 18일
I think you can use bar, not histogram
bar(error)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by