当前位置:网站首页>Matlab programming example: how to count the number of elements in a cell array
Matlab programming example: how to count the number of elements in a cell array
2022-06-26 11:20:00 【falwat】
Problem description
There are multiple repeating elements in an array , Such as {' Basketball ', ' football ', ' Table Tennis ', ' football ', ' Table Tennis ', ' football ', ' Volleyball '}, How to count the number of each ball ? ( Please think for a few seconds !!)
A feasible method
- Use
unique()Function to construct a sphere dictionary ( No duplicates ), - Use
strcmp()Functions andfind()Function to judge in turnballsThe category of each element in the , Increase the number of corresponding categories .
The code is as follows :
balls = {' Basketball ', ' football ', ' Table Tennis ', ' football ', ' Table Tennis ', ' football ', ' Volleyball '};
dict_ball = unique(balls);
count_ball = zeros(size(dict_ball));
for k = 1:length(balls)
idx = find(strcmp(balls{k}, dict_ball));
count_ball(idx) = count_ball(idx)+1;
end
The operation results are as follows :
Use pie(), pie3() Draw the pie chart :
pie(count_ball,dict_ball);
title(' Proportion of balls ')

If you have a better way , Welcome to the comment area !
边栏推荐
- Cet article présente la moyenne mobile quadratique linéaire et le fonctionnement simple d'Excel pour réaliser la prédiction des séries chronologiques dans la modélisation.
- 杜比全景音效简介
- 机器学习PCA——实验报告
- UDP Flood攻击防御原理
- openresty 概述
- 【深度学习理论】(6) 循环神经网络 RNN
- That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade
- Redux related usage
- I want to know whether flush is a stock market? Is it safe to open a mobile account?
- 机器学习线性回归——实验报告
猜你喜欢

3、 Linked list exercise

Redis best practices? If I don't feel excited after reading it, I will lose!!

PC QQ hall upload update modify VersionInfo

9、 Beautify tables, forms, and hyperlinks

Easyx-----c语言实现2048

Svn installation configuration

Excel operation of manual moving average method and exponential smoothing method for time series prediction

Flannel's host GW and calico

(typora picture bed) Alibaba cloud OSS building picture bed +picgo uploading picture detailed tutorial

sliding window
随机推荐
代码规范 & 详细解释 husky、prettier、eslint、lint-staged 的作用和使用
机器学习LDA——实验报告
Machine learning deep neural network -- Experimental Report
openresty 概述
24 个必须掌握的数据库面试问题!
C language -- operators and expressions
That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade
10 years' experience in programmer career - for you who are confused
Black squares in word
[deep learning theory] (6) recurrent neural network RNN
Flannel's host GW and calico
Cet article présente la moyenne mobile quadratique linéaire et le fonctionnement simple d'Excel pour réaliser la prédiction des séries chronologiques dans la modélisation.
Basic use of express in nodejs
深度理解STM32的串口实验(寄存器)【保姆级教程】
深度学习中的FLOPs和Params如何计算
Work report (3)
laravel-admin 用 原生JS实现声音提示,及自动播放
MQTT断开重连
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
Huawei secoclient reports an error "accept return code timeout" [svn adapter v1.0 exclamation point]