How to use bar() to plot

3 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by