计算列中字符串的出现次数-Matlab [英] Count occurences of strings in column - Matlab

查看:148
本文介绍了计算列中字符串的出现次数-Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列包含以下数据:
尺寸:100x7

I have a column with the following data:
Size: 100x7

val =

USA
USA
France
USA
France

我想在饼图上显示数据.为此,我需要知道此栏中有多少美国发生,依此类推.
我读到有关函数unique,accumarray的信息,但我没有成功
我想获得一些建议.
谢谢.

I want to show the data on pie chart. to do this, I need to know how much USA occur in this column, and so on.
I read about the functions unique,accumarray but I dont success
I would like to get some suggestions how to do that.
Thanks.

推荐答案

您可以将uniquehistc-

%// Get countries and their occurences
[countries,~,id] = unique(cellstr(val),'stable')
occurrences = histc(id,1:max(id))

然后您可以将国家/地区名称出现的次数显示为表格-

You can then display the number of occurrences against the country names as a table -

>> table(countries,occurrences)
ans = 
    countries    occurrences
    _________    ___________
    'USA'        3          
    'France'     2       

将输出显示为饼图-

>> pie(occurrences,countries)

这篇关于计算列中字符串的出现次数-Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆