How to multiply a window function to one dimension?

5 ビュー (過去 30 日間)
John
John 2014 年 6 月 6 日
編集済み: John 2014 年 6 月 16 日
Here is a Matlab script to apply a fixed window function along one dimension. Although it works, but is not elegant as a Matlab script. Can it be made more elegant? Thanks.
[L1, L2, L3, L4, L5, L6] = size(fids);
for n1=1:L1
for n3=1:L3
for n4=1:L4
for n5=1:L5
for n6=1:L6
fids(n1,:,n3,n4,n5,n6) = fids(n1,:,n3,n4,n5,n6) .* window;
end
end
end
end
end
Where window is a vector with the size equal to L2.
  3 件のコメント
José-Luis
José-Luis 2014 年 6 月 12 日
編集済み: José-Luis 2014 年 6 月 12 日
Jian, as an aside: It would be nice if you gave some more feedback on the questions you have asked in the past. Please accept answers if they solved your problem or explain why a given answer does not do what you wanted.

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

採用された回答

Chad Greene
Chad Greene 2014 年 6 月 6 日
編集済み: Chad Greene 2014 年 6 月 6 日
Since you didn't give us your fids or window data, I'll make them up:
fids = rand(4,5,6,7,8,9);
window = 2*ones(1,5)-3;
Now your entire script you provided in your question can be replaced by this:
fids = bsxfun(@times,fids,window);
  2 件のコメント
Image Analyst
Image Analyst 2014 年 6 月 13 日
You are incorrect. Chad's fids is a 6 dimensional array.
John
John 2014 年 6 月 16 日
編集済み: John 2014 年 6 月 16 日
Hi, Chad:
Thanks for the good answer. I understand it now. Matlab's doc on @times is very primitive.
So, if the vector is to apply to the 4th dimension, your vector should be defined as:
window = 2*ones(1,1,1,7)-3;
Back to the vector in the original question. It has to be arranged as
window = reshape(window, [1,size(window)]);
fids = bsxfun(@times,fids,window);
and if the multiplication is to the 4th dimension, arrange it as:
window = reshape(window, [1,1,1,size(window)]);
Correct?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by