简体   繁体   English

如何将两列单元格数组转换为带点矩阵(单元格数组每一行中的每对元素)MATLAB

[英]how to convert two-columned cell array into matrix with points (each pair of elements from each row of cell array) MATLAB

I have an cell Array (input) like this: 我有一个像这样的单元格数组(输入):

A(1,1) = {[1 2]};   A(1,2) = {[4 5 6]};

now for each row of A (in this case only 1) I would like to obtian the vector of points like this: 现在,对于A的每一行(在这种情况下仅为1),我想使点向量像这样:

A_row1 =[ 1 4; 1 5; 1 6; 2 4; 2 5; 2 6]

I wonder if there is any method to cope with this without a loop? 我想知道是否有任何方法可以解决此问题而无需循环?

How about: 怎么样:

[x, y] = ndgrid(A{1}, A{2})
B = [x(:) y(:)]

I think this should do the trick: 我认为这应该可以解决问题:

B = sortrows([repmat(A{1}',size(A{2},2),1) repmat(A{2}',size(A{1},2),1)])

B =

 1     4
 1     5
 1     6
 2     4
 2     5
 2     6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将单元格数组的每个单元格中的第一个值替换为另一个单元格数组MATLAB中的值 - Replace the first value in each cell of a cell array with the value from another cell array MATLAB 如何将矩阵转换为单元格数组 - How to convert matrix to cell array Matlab 从单元阵列到矩阵阵列的转换 - Matlab transformation from cell array to matrix array 如何在MATLAB中将矩阵的单元格数组转换为列矩阵? - How to convert cell array of matrices into a column matrix in MATLAB? 在matlab的每个单元格数组元素中循环 - loop in each cell array element in matlab MATLAB:从2个1Darray中合并axb矩阵(或2D数组),并从另一个数组填充每个单元格 - MATLAB: ceate a x b matrix (or 2D array) from 2 1Darrays, and populate each cell from another array 如何操作二维数组/矩阵的每个单元? - How to opperate each cell of 2D array/matrix? 如何在二维数组的每个单元格中找到具有相同数值的行? - How to find a row with the same numeric value in each cell in a two dimensional array? 读取一个 csv 两列文件并将其存储在二维数组 JavaScript 中 - Read a csv two-columned file and store it in 2D array JavaScript Matlab:从索引获取单元格数组的元素 - Matlab: Get elements of Cell Array from Indices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM