Operation on matrix_for beginner

1 回表示 (過去 30 日間)
Momo
Momo 2013 年 1 月 25 日
Dear all, I have a matrix M with 300 rows and 1020 columns, size(M)= 300, 1020; and a vector V= 1 2 3 4 ....1020; size(v)= 1, 1020; I want to divide all the matrix elements with the vector u, u=(1 /(exp(a*V/c)-1) + 1); where V is the row vector. (a and c are constants) I made the code below, but it doesn't work:
% code
u= 1/(exp(a*V(1,:)/c)-1);
[n,m]=size(M);
for i=1:n
NM= M(i,:)*(u(1,:)+1);
end
  1 件のコメント
Jan
Jan 2013 年 1 月 25 日
"It doesn't work" is an expression which should be explained with more details in a forum.

サインインしてコメントする。

回答 (1 件)

Evgeny Pr
Evgeny Pr 2013 年 1 月 25 日
編集済み: Evgeny Pr 2013 年 1 月 25 日
u = 1 ./ (exp(a * V / c) - 1) + 1
Out = bsxfun(@rdivide, M, u)
For example:
M = rand(3, 12)
V = rand(1, 12)
a = 10
c = 20
u = 1 ./ (exp(a * V / c) - 1) + 1
Out = bsxfun(@rdivide, M, u)
  1 件のコメント
Momo
Momo 2013 年 1 月 25 日
Thanks it works.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by