[英]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.