MATLAB中的矩阵运算 [英] A matrix operation in MATLAB

查看:50
本文介绍了MATLAB中的矩阵运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试简化我的代码,并且遇到一个小问题.让

I am trying to simplify my code a bit, and I am across a small question. Let

v  = [1; 2; 3];
a1 = [4; 5; 6];
a2 = [7; 8; 9];
A  = [a1, a2];

我的目标是计算

u = [v.*a1, v.*a2]

通过仅使用v一次.这可能吗?

by only using v one time. Is this possible?

推荐答案

是的,您可以使用 bsxfun ,例如:

yes, you can do this using bsxfun, for example:

u = bsxfun(@times,A,v);

或通过使用repmat

u= repmat(v,[1 2]).*A;

或通过使用kron

u= kron(v,[1 1]).*A;

或最后,仅使用矩阵乘法:

or last, just using matrix multiplication:

u = v*[1 1].*A;

我敢肯定还有更多的方法,但是我会在这里停止...

I'm sure there are even more ways, but I'll stop here...

这篇关于MATLAB中的矩阵运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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