使用matlab中的其他向量元素创建矩阵(Create a matrix using elements of other vectors in matlab)

编程入门 行业动态 更新时间:2024-10-18 20:31:40
使用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))]

更多推荐

本文发布于:2023-08-02 20:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   矩阵   元素   matlab   vectors

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!