MATLAB Fundamentals>>Representing Discrete Categories

MATLAB Fundamentals>Specialized Data Types>Representing Discrete Categories>(1/6) Introduction

Representing Discrete Categories

When text labels are intended to represent a finite set of possibilities, a string array may use more memory than a categorical array. There are functions designed to work with categories of data, so if your text describes a group or category, this is often the best data type.
当文本标签旨在表示一组有限的可能性时,字符串数组可能比分类数组使用更多的内存。有些函数是为处理数据类别而设计的,因此,如果您的文本描述了一个组或类别,这通常是最好的数据类型

MATLAB Fundamentals>Specialized Data Types>Representing Discrete Categories>(2/6) Converting to and Operating on Categoricals

This code sets up the activity.

x = ["C","B","C","A","B","A","C"]

This line of code would produce an error.

% histogram(x)

说明1:You can convert a string array to a categorical using the categorical function.

任务1:Convert x into a categorical array named y.

解答:

y = categorical(x)

说明2:Categorical arrays take up less memory than cell arrays of strings.

任务2:Issue the whos x y command to see how much memory each variable uses.

解答:

whos x y

任务3:

You can see the categories represented in a categorical array using the categories function on the categorical array.

解答:

cats = categories(y)

任务4:

Create a variable named iC which contains values of true corresponding to the values in y that equal C.

解答:

iC = y == "C"

任务5:

Create a variable named iNB which contains values of true corresponding to the values in y that are not equal to B.

解答:

iNB = y ~= "B"

附加练习:Try indexing into y with iC and iNB.

解答:

iCidx = y(iC)
iNBidx = y(iNB)

笔记:

(1)a string array may use more memory than a categorical array字符串数组比分类数组占用更多内存;

(2)任务4和5后面部分可以不使用括号,执行运算顺序为从又向左,即先计算“等于”或“不等于”逻辑,在将结果赋值给左边变量。

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-18 07:06:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-18 07:06:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-18 07:06:05       87 阅读
  4. Python语言-面向对象

    2024-01-18 07:06:05       96 阅读

热门阅读

  1. Hadoop之mapreduce参数大全-7

    2024-01-18 07:06:05       45 阅读
  2. flutter 播放SVGA动图

    2024-01-18 07:06:05       63 阅读
  3. Spring Boot整合Junit

    2024-01-18 07:06:05       46 阅读
  4. esp32-c-简单应用笔记

    2024-01-18 07:06:05       45 阅读
  5. 消息队列之RabbitMQ工作模式

    2024-01-18 07:06:05       48 阅读
  6. Spring Boot整合Junit,@RunWith和@SpringBootTest的使用

    2024-01-18 07:06:05       50 阅读
  7. LUA 对象转excel

    2024-01-18 07:06:05       41 阅读
  8. Bitcoin的Covenants——合同化管理UTXO的花费方式

    2024-01-18 07:06:05       74 阅读
  9. 在 Centos 7.9 中,安装与配置 Docker 20.10.18

    2024-01-18 07:06:05       54 阅读
  10. flask不使用flask-login插件

    2024-01-18 07:06:05       58 阅读