在Matlab中访问单元格中的向量 [英] Access to a vector in cell in Matlab
本文介绍了在Matlab中访问单元格中的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C
是由一些向量组成的单元格:
C
is a cell consisting of some vectors:
C = {[1, 2], [2, 3]};
我想读取C
中第一个向量的第一项.但是我不能使用以下内容:
I want to read the first entry of the first vector in C
. But I can not use the following:
C{1}[2]
我收到以下错误:
错误:括号或括号不平衡或出现意外情况.
Error: Unbalanced or unexpected parenthesis or bracket.
如何使它读取值?
推荐答案
您可以像这样访问单元格数组中矩阵的各个元素:
You can access individual elements of matrices in cell array like this:
C{n,m}(ii,jj);
这将为您提供单元格数组的索引(n,m)
处的矩阵元素(ii,jj)
.
This will give you element (ii,jj)
of the matrix at index (n,m)
of the cell array.
因此,对于您的特定示例,
Hence, for your particular example,
val = C{1,1}(1,1)
(或val = C{1}(1)
)
会将单元格数组中第一个向量的第一个元素的值分配给变量val
.
will assign the value of the first element of the first vector in the cell array to the variable val
.
这篇关于在Matlab中访问单元格中的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文