选择的第n个元件中的一个matlab单元阵列 [英] choosing the nth element in a matlab cell array

查看:145
本文介绍了选择的第n个元件中的一个matlab单元阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单元阵列VsCell含维1000x1(或更多)。在VsCell每一项都是一个501x567矩阵。我想提取占据包含在小区中的所有矩阵的位置的元件。基本上是这样的:

I have a cell array VsCell with dimension 1000x1 (or more). Each item in VsCell is a 501x567 matrix. I want to extract elements occupying a position in all the matrices contained in the cell. Basically something like:

VsCell {:}(1,1) - 对在细胞阵列的所有的第一单元
VsCell {:}。(2,1) - 对所有的第一行2中的阵列中的电池元件

VsCell{:}(1,1) - for all the first elements of the arrays in the cell VsCell{:}(2,1) - for all the first row 2 elements of the arrays in the cell.

随后,我打算把这些选择的均值或中位数和填单[501x567]矩阵阵列,这将重新present均值/中位数/的VsCell阵列例如等平均(VsCell {:}(1,1))。

Subsequently, I intend to take the mean or median of these selection and fill a single [501x567] matrix array, which would represent the mean/median/etc of the VsCell arrays e.g. mean(VsCell{:}(1,1)).

我试过VsCell {:}(1,1) - 但它返回

I tried VsCell{:}(1,1) - but it returns "Bad cell reference operation."

此外,有没有一种方法很少或没有对循环/ cellfun实现这一目标?
这种使用网上找到我无法真正实现。

Also, is there a way to achieve this with little or no for loops/cellfun? I couldn't really achieve this using examples found online.

非常感谢您的宝贵时间,我很高兴能进一步明确如果需要的话。

Thank you very much for your time, I am glad to clarify further if need be.

推荐答案

我不认为你正在试图做什么可以用细胞来完成,没有循环或 cellfun ,那是。细胞是异构数据结构,也不能保证每一个元素将有一个兼容的形状。哎呀,你的电池单元3号甚至可以是另一个单元格,或字符串,或自定义类的实例!我只是说,我并不觉得奇怪,细胞不能被索引到的方式你想。

I don't think what you're trying to do can be done with cells, without loops or cellfun, that is. Cells are heterogeneous data structures, there's no guarantee that each element will have a compatible shape. Heck, element number 3 in your cell could even be another cell, or a string, or a custom class instance! I'm just saying that I don't find it surprising that cells can't be indexed into in the way you're trying to.

不过,你的可以的CON enate你的手机变成一个更高维数组,并与工作:

However, you can concatenate your cell into a higher-dimensional array, and work with that:

VsMat = cat(3,VsCell{:}); % cell as comma separated list
MatMeans = mean(VsMat,3); % mean along dimension 3, where they are concatenated
MatMedians = median(VsMat,3);
MatSums = sum(VsMat,3);

使用数组应该会更快,无论如何,所以除了调用(这是慢)的单权衡,你使用均匀阵列很可能更好反正。

Working with arrays should be faster anyway, so except for the single trade-off of calling cat (which is slow), you're probably better off using homogeneous arrays anyway.

这篇关于选择的第n个元件中的一个matlab单元阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆