필터 지우기
필터 지우기

Plotting the Bar chart in Matlab

조회 수: 9 (최근 30일)
Satish Jawalageri
Satish Jawalageri 2021년 5월 6일
답변: Ayush 2024년 7월 9일 8:15
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.
Thanks,
Satish J

답변 (1개)

Ayush
Ayush 2024년 7월 9일 8:15
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)

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by