元胞数组创建与元素读取&未定义与 ‘cell‘ 类型的输入参数相对应的运算符 ‘==‘。

本文介绍了如何在MATLAB中创建元胞数组,包括两种不同的初始化方法,并展示了如何读取元胞数组的元素。同时,讲解了正确比较元胞数组元素与字符串的方式,即使用`cellstr`转换后再用`strcmp`进行比较,避免出现与'cell'类型不匹配的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.创建一个元胞数组testcell

方式1:

testcell = cell(2,3);

testcell{1,1} = {'monday','mon'};

testcell{1,2} = {'tuesday ','tue'};

testcell{1,3} = {'wednesday','wed'};

testcell{2,1} = {'thursday','thu'};

testcell{2,2} = {'friday','fri'};

testcell{2,3} = {'saturday','sat'};

方式2:

testcell = { {'monday','mon'},{'tuesday ','tue'},{'wednesday','wed'};{'thursday','thu'},{'friday','fri'},{'saturday','sat'}};

2.读取元素

>> testcell(1,1)

ans =

  1×1 cell 数组

    {1×2 cell}

>> testcell{1,1}(1,1)

ans =

  1×1 cell 数组

    {'monday'}

>> testcell{1,1}(1,2)

ans =

  1×1 cell 数组

    {'mon'}

3.判断元胞数组某个元素是否与某个字符串相等:先用cellstr转为字

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值