如何在Matlab中将向量添加到矩阵中?

编程入门 行业动态 更新时间:2024-10-24 21:22:24
本文介绍了如何在Matlab中将向量添加到矩阵中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何通过将向量的i索引添加到i行中的所有成员的方式,如何将向量添加到Matlab中的矩阵?

How can I add a vector to a matrix in Matlab, in a manner that the i's index of the vector would be added to all the members in the i's row?

例如:

A = [1 2 3; 4 5 6; 6 7 8] v = [1; 2; 3]

所需的结果是:

[2 3 4; 6 7 8; 9 10 11]

非常感谢.

推荐答案

bsxfun的替代方法是使用 repmat ,并重复列向量v与A具有列的次数相同:

An alternative to bsxfun is to use repmat and repeat the column vector v as many times as A has columns:

A = [1 2 3; 4 5 6; 6 7 8]; v = [1; 2; 3] A = A + repmat(v,1,3);

更多推荐

如何在Matlab中将向量添加到矩阵中?

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

发布评论

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

>www.elefans.com

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