필터 지우기
필터 지우기

Error when plotting a stacked bar chat.

조회 수: 1 (최근 30일)
mpho bosupeng
mpho bosupeng 2023년 12월 23일
댓글: Sulaymon Eshkabilov 2023년 12월 23일
Hello I used the following code on MATLAB R2021a to obtain a stacked bar chat but I get the following error:
Error using bar (line 139)
Input arguments must be numeric, datetime, duration or categorical.
x = ["1980M11"; "1985M01"; "1986M01"; "1991M09"; "1994M07"; "1997M07"; "2007M07"; "2012M06"; "2015M01"; "2017M11 to date"];
y =[50 50 0; 75 25 0; 65 35 0; 60 30 10; 70 30 0; 65 35 0; 60 40 0; 55 45 0; 50 50 0; 45 55 0];
bar(x,y,'stacked')
However, when I use MATLAB online I get the bar chat without issues but its not high quality (png) and I cannot edit the work. Help me to run this on R2021a.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 12월 23일
Here is the corrected code:
x = ["1980M11"; "1985M01"; "1986M01"; "1991M09"; "1994M07"; "1997M07"; "2007M07"; "2012M06"; "2015M01"; "2017M11 to date"];
y =[50 50 0; 75 25 0; 65 35 0; 60 30 10; 70 30 0; 65 35 0; 60 40 0; 55 45 0; 50 50 0; 45 55 0];
x = categorical(x);
bar(x,y,'stacked')
  댓글 수: 2
mpho bosupeng
mpho bosupeng 2023년 12월 23일
Thank you so much @Sulaymon Eshkabilov 🙏.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 12월 23일
Most welcome! Glad to be of some help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by