フィルターのクリア

How to plot more data than categories

2 ビュー (過去 30 日間)
Inmaculada Sardaña Ortega
Inmaculada Sardaña Ortega 2019 年 6 月 7 日
回答済み: Prasanth Sikakollu 2019 年 6 月 9 日
Does anybody know how can I plot in same bar plot more than 2 files of categorical data if I only have 2 categories? For example, if I have:
data=[1 2
2 1
1 3]
X_cat=categorical({'Case1','Case2'})
How to get bar(data,'grouped')?
Thanks in advance!
  2 件のコメント
dpb
dpb 2019 年 6 月 7 日
編集済み: dpb 2019 年 6 月 7 日
Sorry, I don't follow what you expect to happen here... :)
Can you show a sketch or describe what you think the bar plot should look like?
ADDENDUM (MUCH LATER)
Or maybe the data are just oriented incorrectly and what is intended is
bar(X_cat,data.','grouped')
??? which yieldsuntitled.jpg
Inmaculada Sardaña Ortega
Inmaculada Sardaña Ortega 2019 年 6 月 9 日
Yes! It was just that. Sorry if I did not explained properly before.
Thank you so much!

サインインしてコメントする。

回答 (1 件)

Prasanth Sikakollu
Prasanth Sikakollu 2019 年 6 月 9 日
bar(y) creates a bar graph with one bar for each element in y. If y is a matrix, then bar groups the bars according to the rows in y.
Here, in your case, data is oriented incorrectly - need to give transpose of data (i.e., data') as input to the bar() function.
The following code would help you solving this problem.
data=[1 2
2 1
1 3]
X_cat=categorical({'Case1','Case2'})
bar(X_cat,data','grouped')
For more information on plotting bar graphs, refer to the following link:

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by