MATLAB/OCTAVE从细胞阵列中不同大小的向量中提取元素 [英] MATLAB/OCTAVE Extracting elements from different sized vectors in a cell array
本文介绍了MATLAB/OCTAVE从细胞阵列中不同大小的向量中提取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的问题,但我无法弄清楚或在任何地方找到它. 我有一个单元格数组,其中c {1}是一个向量,c {2}是一个向量,但长度不同,最大为c {i}.我想要的是一个向量[c {1}; c {2}; c {3} ... c {i}].最有效的方法是什么?
I have a simple question but I can't figure it out or find it anywhere. I have a cell array where c{1} is a vector and c{2} is a vector but of different lengths, up to c{i}. What I want is one vector that is [c{1};c{2};c{3}...c{i}]. What is the most efficient way to do this?
推荐答案
以下一线甚至可以用于完全不一致的输入:
The following one-liner even works for completely inconsistent inputs:
result = [cell2mat(cellfun(@(x) x(:), A, 'uni', 0)')]'
示例:
针对:
A{1} = [1, 2, 3, 4, 5];
A{2} = [6; 7; 8; 9];
A{3} = [10, 12; 11, 13];
它返回:
result =
1 2 3 4 5 6 7 8 9 10 11 12 13
这篇关于MATLAB/OCTAVE从细胞阵列中不同大小的向量中提取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文