访问1x1 matlab单元的内容 [英] Accessing the contents of a 1x1 matlab cell
问题描述
我不确定这个术语,但是我已经将数据从文本文件读取到1x1单元格数组P
中.检查P
时,它在(1,1)位置列出了"<142x2单元格>".从那里,我可以双击它,它会打开到我真正想要的142x2单元格中.问题是,我不知道如何通过代码将数据从1x1单元阵列转换为142x2单元阵列.
另外,我在任何地方都找不到大括号表示的内容.
I'm not sure about the terminology, but I have read data from a text file into a 1x1 cell array P
. When examining P
, it lists "<142x2 cell>" in the (1,1) position. From there I can double-click this and it opens up into the 142x2 cell that I actually want. The issue is, I don't get how to manipulate this data via code to convert from the 1x1 cell array to the 142x2 cell array.
Also, I cannot find anywhere what the curly brackets denote.
推荐答案
我不知道如何通过代码将数据从1x1单元格数组转换为142x2单元格.
单元格数组P
实际上是一个1x1的单元格数组,它依次包含另一个单元格数组142x2.使用textscan
时,这种类型的输出非常常见.要访问内部单元格数组,只需使用花括号({}
),如下所示:
The cell array P
is actually a 1x1 cell array, which in turn contains another cell array 142x2. This type of output is very common when using textscan
. To access the inner cell array, you can simply use curly braces ({}
), like so:
Q = P{1}; // or P{:} if you're certain that P holds only one cell
生成的Q
应该包含您的142x2单元阵列.我通常通过执行P = P{:}
来拉平" P
,而无需使用中间变量.
The resulting Q
should hold your 142x2 cell array. I usually "flatten" P
by doing P = P{:}
, without using an intermediate variable.
此外,我在任何地方都找不到大括号表示的内容.
您是否已阅读 MATLAB有关特殊字符的文档?它是这样的:
Have you read MATLAB's documentation about special characters? Here's what it says:
在单元格数组分配语句中使用大括号.例如,
A(2,1) = {[1 2 3; 4 5 6]}
或A{2,2} = ('str')
.有关{ }
的更多信息,请参见help paren
.
Curly braces are used in cell array assignment statements. For example,
A(2,1) = {[1 2 3; 4 5 6]}
, orA{2,2} = ('str')
. Seehelp paren
for more information about{ }
.
我也敦促您阅读以下(非常)相关的问题:使用{}和()访问单元格元素之间的区别(大括号与括号)
I would also urge you to read the following (very) related question: Difference between accessing cell elements using {} and () (curly braces vs. parentheses)
这篇关于访问1x1 matlab单元的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!