How to use bar() to plot

4 visualizaciones (últimos 30 días)
Victoria Morrison
Victoria Morrison el 10 de En. de 2021
Respondida: William el 10 de En. de 2021
%% 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?

Respuesta aceptada

William
William el 10 de En. de 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.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by