bar chart for an array
显示 更早的评论
I'm trying to create a bar chart for a matrix, its a 1x30 but I only want the 0, 10th, 20th and 30th values.
I've tried many formats such as in the image but I cannot manage to get it working.
Any suggestions out there?
采纳的回答
Ameer Hamza
2018-5-4
编辑:Ameer Hamza
2018-5-4
I MATLAB, use the following syntax to index into an array.
bar([1 10 20 30], mean_1_1_walk([1 10 20 30]))
Also in MATLAB indexing start from 1, unlike some other programming languages (such as c/c++, java, python) where indexing starts from 0.
8 个评论
"... unlike most other programming languages."
"... unlike one other particular programming language."
That sorted it, thank you.
Also note you can write expressions like
mean_1_1_walk([1:10:end])
besides a list of specific indices.
@dpb OP is indexing them like [1 10 20 30] for some reason. Therefore I wrote it like that.
bar([1 10 20 30], [mean_1_1_walk([1 10 20 30])' mean_1_2_walk([1 10 20 30])']);
Indeed he did, but he also started counting from 0 instead of 1. It's quite possible he didn't know could write an expression; was simply giving alternate syntax as tutorial additional information.
Would anyone know how to change the colours of these bars too?
bar([1 10 20 30], [mean_1_1_walk([1 10 20 30])' mean_1_2_walk([1 10 20 30])']);
You can find several examples on documentation page which will help you to do this: https://www.mathworks.com/help/matlab/ref/bar.html#d119e66370.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Bar Plots 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
