Redian新闻
>
请问怎样让一m长的向量和一mxn的矩阵相乘,仍为mxn
avatar
请问怎样让一m长的向量和一mxn的矩阵相乘,仍为mxn# Computation - 科学计算
g*s
1
比如要一个 1*3的向量,乘一个3*100的矩阵.
向量的第i个元素乘矩阵的第i行,结果为3*100的矩阵. 请问不用for循环matlab能行吗?`
avatar
g*i
2
many ways. one:
diag(v)*A

【在 g******s 的大作中提到】
: 比如要一个 1*3的向量,乘一个3*100的矩阵.
: 向量的第i个元素乘矩阵的第i行,结果为3*100的矩阵. 请问不用for循环matlab能行吗?`

avatar
g*s
3
you are really an expert! Thank you so much!

吗?`

【在 g***i 的大作中提到】
: many ways. one:
: diag(v)*A

avatar
g*s
4
请问怎样从一个3*100 的矩阵的第 i 行减去一个长度为3的向量的第i个元素? 好象这个
不用循环是不行了.



【在 g******s 的大作中提到】
: you are really an expert! Thank you so much!
:
: 吗?`

avatar
l*i
5
A=A-diag(v)*ones(size(A))

【在 g******s 的大作中提到】
: 请问怎样从一个3*100 的矩阵的第 i 行减去一个长度为3的向量的第i个元素? 好象这个
: 不用循环是不行了.
:
: 行

avatar
r*y
6

Let a is your vector, and B is the matrix,
repmat(a', 1, 100) .* B

【在 g******s 的大作中提到】
: 比如要一个 1*3的向量,乘一个3*100的矩阵.
: 向量的第i个元素乘矩阵的第i行,结果为3*100的矩阵. 请问不用for循环matlab能行吗?`

avatar
r*y
7

B - repmat(a', 1, 100)
You really need to learn some basic about matlab ah.

【在 g******s 的大作中提到】
: 请问怎样从一个3*100 的矩阵的第 i 行减去一个长度为3的向量的第i个元素? 好象这个
: 不用循环是不行了.
:
: 行

avatar
w*d
8
why bother? In the new version of Matlab, for loop won't slow your program
down.

【在 g******s 的大作中提到】
: 请问怎样从一个3*100 的矩阵的第 i 行减去一个长度为3的向量的第i个元素? 好象这个
: 不用循环是不行了.
:
: 行

avatar
s*t
9
explain more?

【在 w**d 的大作中提到】
: why bother? In the new version of Matlab, for loop won't slow your program
: down.

avatar
w*d
10
i need to dig out my notes. It might be related to the issue of memory.
A senior engineer from mathworks once gave
several lectures on Matlab. He told us so.

【在 s***t 的大作中提到】
: explain more?
avatar
s*t
11
as far as i know, the matrix operations in matlab are implemented with BLAS.
plus matlab is an intepreter, not a compiler (i know you can compile matlab
code, but it's another story). these two reasons make it hard to believe
for loops are as fast as matrix operations in matlab.
i would certainly want to know any new development in matlab.

【在 w**d 的大作中提到】
: i need to dig out my notes. It might be related to the issue of memory.
: A senior engineer from mathworks once gave
: several lectures on Matlab. He told us so.

avatar
w*d
12
i know it is hard to beat BLAS. In my understanding, the for-loop might be not
as effecient as BLAS, but won't be slower than the standard for-loop in C or
Fortran.
But the main reason for the slow speed of for-loop is because during
the for-loop, lots of intermediate variables are generated.
In the new version, it is not done in that way if the matrix variable
has been initialized.
Mathworks has done something to improve the speed. You can go to the website of mathworks, and search with
keywor

【在 s***t 的大作中提到】
: as far as i know, the matrix operations in matlab are implemented with BLAS.
: plus matlab is an intepreter, not a compiler (i know you can compile matlab
: code, but it's another story). these two reasons make it hard to believe
: for loops are as fast as matrix operations in matlab.
: i would certainly want to know any new development in matlab.

avatar
s*t
13
sorry, just read my post again. it seems i always left some critical words
in my sentences. i meant to say "i would certainly WANT TO know any new
development" :)
anyways, why search for "jitter"? isn't it variation in sampling time? i
searched and didn't see many relavant results. can you give some links?

【在 w**d 的大作中提到】
: i know it is hard to beat BLAS. In my understanding, the for-loop might be not
: as effecient as BLAS, but won't be slower than the standard for-loop in C or
: Fortran.
: But the main reason for the slow speed of for-loop is because during
: the for-loop, lots of intermediate variables are generated.
: In the new version, it is not done in that way if the matrix variable
: has been initialized.
: Mathworks has done something to improve the speed. You can go to the website of mathworks, and search with
: keywor

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。