How to use bar() to plot

조회 수: 4 (최근 30일)
Victoria Morrison
Victoria Morrison 2021년 1월 10일
답변: William 2021년 1월 10일
%% Task 3 - PLOT
figure(1)
subplot(2, 2, 1)
plot(avgCO2, Time2);
subplot(2, 2, 2)
plot(avgTA, Time1);
subplot(2, 2, 3)
bar(prct_inc, Time2);
subplot(2, 2, 4)
plot(avgTA, avgCO2)
Error using bar (line 182)
XData values must be unique.
Error (line 52)
bar(prct_inc, Time2);
How do I fix this?

채택된 답변

William
William 2021년 1월 10일
I suspect the arguments to your plot() functions are reversed, When you type plot(a,b), Matlab puts 'a' on the x-axis ahd 'b' on the y axis. So, when you write 'plot(avgCO2, Time2);', it is going to put time on the vertical axis and avgCO2 on the horizontal axis. That's probably the opposite of what you wanted.
When it got to the bar-graph bar(prct_inc, Time2), it used prct_inc as the independent variable (the x-axis) and apparently found two or more values that were identical, which is not allowed in a bar-graph. If Time2 were plotted on the x-axis using bar(Time2,prct_inc), this probably wouldn't happen since you wouldn't normally have two identical values of time.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by