Plotting the Bar chart in Matlab
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all,
I am plotting the bar chart in matlab with the following code,
x = [1 2 3];
figure,
bar(x,[3 2 1;6 5 4;9 8 7])
Here, I am getting the following chart when I run it, but it should be (3,6,9) should be below the 1(x-axis), (2,5,8) under the 2(x-axis), similarly (1,4,7) in 3(xaxis).
It would be great, if anyone could help.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/609550/image.jpeg)
Thanks,
Satish J
0 Commenti
Risposte (1)
Ayush
il 9 Lug 2024
Hi,
The data in your matrix is being plotted in columns rather than rows. To achieve the desired grouping, you should transpose the matrix. You can do this by using the transpose operator ('). Here's the updated code:
x = [1 2 3];
y = [3 2 1; 6 5 4; 9 8 7]';
figure,
bar(x, y)
0 Commenti
Vedere anche
Categorie
Scopri di più su Bar Plots in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!