使用matlab中的其他向量元素创建矩阵(Create a matrix using elements of other vectors in matlab)
我有两个向量a,b
a=[1; 2; 3; 4] b=[1; 2; 3]我想创建一个看起来像这样的矩阵
c=[1 1; 2 1; 3 1; 4 1; 1 2; 2 2; 3 2; 4 2; 1 3; 2 3; 3 3; 4 3]I have two vectors a, b
a=[1; 2; 3; 4] b=[1; 2; 3]And I want to create a matrix which will look like this
c=[1 1; 2 1; 3 1; 4 1; 1 2; 2 2; 3 2; 4 2; 1 3; 2 3; 3 3; 4 3]最满意答案
这是另一种方式!
c = [repmat(a,numel(b),1),sort(repmat(b,numel(a),1))]Here is yet another way!
c = [repmat(a,numel(b),1),sort(repmat(b,numel(a),1))]更多推荐
发布评论