Matlab:将向量添加到矩阵 [英] Matlab: add vector to matrix

查看:227
本文介绍了Matlab:将向量添加到矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3XN矩阵,表示3D坐标列表,类似

I have a 3XN matrix representing a list of 3D coordinates,something like

33    33    33    33    34    34    34    34    34    35    35
17    18    19    20    16    17    18    19    20    16    17
10    10    10    10    10    10    10    10    10    10    10 

我想将所有坐标移动某个向量v=[1 2 3],即将3D向量添加到矩阵的每一列.

I want to shift all coordinates by some vector v=[1 2 3], that is add the 3D vector to each column of the matrix.

我知道如何使用for循环来执行此操作,但是如何不使用循环来执行此操作?当然有办法...

I know how to do that with a for loop, but how can I do it without a loop? Surely there's a way...

推荐答案

您的意思是这样吗?

D=[33    33    33    33    34    34    34    34    34    35    35;
17    18    19    20    16    17    18    19    20    16    17;
10    10    10    10    10    10    10    10    10    10    10 ];

A=[1 2 3]';

C= bsxfun(@plus, D, A)

C =

    34    34    34    34    35    35    35    35    35    36    36
    19    20    21    22    18    19    20    21    22    18    19
    13    13    13    13    13    13    13    13    13    13    13

这篇关于Matlab:将向量添加到矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆