Multi dimensional array scaling

Given the matrix A (where A is X by Y by Z matrix. Scale the matrix A such that every element in the kth page is scaled by 5k for k = 1,2,3...Z.
I would have to produce a matrix B such that with element wise multiplication with matrix A it gives me the scaled version.
I have tried messing around with repmat and reshape functions but I can't seem to get it

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 19 日
編集済み: Azzi Abdelmalek 2014 年 1 月 19 日

0 投票

[n,m,p]=size(A)
out=5*reshape(repmat(1:p,n*m,1),size(A)).*A

その他の回答 (1 件)

Jan
Jan 2014 年 1 月 19 日
編集済み: Jan 2014 年 1 月 19 日

0 投票

What about starting will a simple loop:
s1 = 10;
s2 = 20;
s3 = 30;
A = rand(s1, s2, s3);
B = A;
for k = 1:s3
B(:, :, k) = B(:, :, k) * 5 * k;
end
Later on I'd prefer bsxfun:
B = bsxfun(@times, A, reshape(5:5:5*s3, 1, 1, s3))

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2014 年 1 月 19 日

コメント済み:

2014 年 1 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by