如何访问单元阵列矩阵? [英] How to Access the Cell array Matrix?
问题描述
有人能告诉我有关单元阵列的索引的信息吗?我已经尝试过搜索它,但是我只能找到不满意的结果(可能是我在谷歌搜索方面不擅长).对于矩阵索引,我找到了一个很好的文档,可以在此处一个>.就我而言,让我们举一个简单的例子.
Could any one tell me about the indexing of a cell Array? I've tried to google it but I could only find unsatisfied result (may be I'm not good in googling). For matrix indexing I found a good document which can be found here. For my case let take a simple example.
a = {ones(10)}
,我想访问a
的第一个元素.像
and I want to access the first element of a
. Something like
a(1,1) % this will give a 10 x 10 matrix but i am not looking for it.
我可以通过将其更改为类似矩阵的方式来实现
I can do it by changing it into a matrix like
a = cell2mat(a);
a(1,1)
ans = 1
但是有什么直接方法可以访问单元阵列子矩阵的第一个元素.
but is there any direct way to access first element of cell array sub matrix.
推荐答案
要访问单元格数组中第一个单元格的第一个元素,您可以执行以下操作:
To access the first element of a the first cell in a cell array, you may do:
a = {ones(10)};
a{1}(1)
如果您具有多维单元格数组,并且其中包含多维数字数组,则可以执行以下操作:
If you have multidimensional cell arrays, with multidimensional numerical arrays inside it, you can do:
a{2,3}(4,5)
这将为您提供单元格(2,3)的元素(4,5).
This will give you element (4,5) of cell (2,3).
这篇关于如何访问单元阵列矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!