Not enough input arguments when using bar()
115 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Raghav Rathi
el 20 de Sept. de 2023
Comentada: Star Strider
el 20 de Sept. de 2023
Hi,
I am trying to generate a bar graph specifically 'Specify Bar Locations as String Vector' from the documentation.
x = ["Outdoor1" "Outdoor2" "Outdoor3" "Outdoor4"];
y = [540 524 515 424];
>> bar(x,y)
Error using bar
Not enough input arguments.
I am not able to figure out why am I getting the above error when the example mentioned in the documentation is pretty much the same but seems to be working.
2 comentarios
Mario Malic
el 20 de Sept. de 2023
Maybe you have a function called bar in your current folder?
which bar
Respuesta aceptada
Star Strider
el 20 de Sept. de 2023
x = categorical(["Outdoor1" "Outdoor2" "Outdoor3" "Outdoor4"]);
y = [540 524 515 424];
figure
bar(x,y)
Another option is to use numerical values, for example 1:4 and then use ‘x’ as tick labels —
x = 1:4;
xl = ["Outdoor1" "Outdoor2" "Outdoor3" "Outdoor4"];
y = [540 524 515 424];
figure
bar(x,y)
set(gca,'XTickLabel',xl)
It all depends on what you want to do.
.
2 comentarios
Más respuestas (1)
Dyuman Joshi
el 20 de Sept. de 2023
Editada: Dyuman Joshi
el 20 de Sept. de 2023
It works fine here - R2023b but does not on my MATLAB app - R2021a.
Since you have R2023a, it means that the support for string array as input to bar must have been implemented in R2023b.
Workaround > Convert x to a categorical array and then plot -
x = ["Outdoor1" "Outdoor2" "Outdoor3" "Outdoor4"];
x = categorical(x);
y = [540 524 515 424];
bar(x,y)
Ver también
Categorías
Más información sobre Bar Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!