How to use bar() to plot
1 view (last 30 days)
Show older comments
%% 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?
0 Comments
Accepted Answer
William
on 10 Jan 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!