Vectorization of for loop and multidimension array

1 回表示 (過去 30 日間)
shahrizan jamaludin
shahrizan jamaludin 2016 年 3 月 8 日
Hello, please help me to vectorize the code below,
%E1 is array
H1=real(E1); %size 144x360
H2=imag(E1); %size 144x360
L=size(array,2); %=360
length=L*2;
T=zeros(size(array,1),length); %size 144x720
M=zeros(size(T)); %size 144x720
h=1:size(array,1); %1:144
for i=0:(L-1)
j=2*i;
T(h,j+1)=H1(h,i+1);
T(h,j+2)=H2(h,i+1);
M(h,j+1)=H2(h,i+1) | H1(h,i+1);
end
Can i vectorized it with bsxfun or arrayfun? Thanks

採用された回答

Stephen23
Stephen23 2016 年 3 月 8 日
編集済み: Stephen23 2016 年 3 月 8 日
Just use indexing properly and then this is trivial:
L = size(array,2);
T(:,2:2:2*L) = imag(array);
T(:,1:2:2*L) = real(array);
M(:,1:2:2*L) = T(:,1:2:end) | T(:,2:2:end);
M(:,2*L) = false;

その他の回答 (0 件)

カテゴリ

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