フィルターのクリア

How to vectorize the following piece of code by removing the two for loops?

1 回表示 (過去 30 日間)
Sadiq
Sadiq 2023 年 12 月 17 日
コメント済み: Sadiq 2023 年 12 月 18 日
clear all;clc
u=[3 4 30 50];% Desired Vector
b=u;
[R,C]=size(b);
P=C/2;
M=2*C;
xo=zeros(1,M);
for k=1:M
for i=1:P
xo(1,k)=xo(1,k)+1*exp(1i*((k-1)*(-pi/2)*sind(u(P+i))+((k-1)^2*pi/(16*u(i)))*cosd(u(P+i))^2));
end
end
xe=zeros(1,M);
for k=1:M
for i=1:P
xe(1,k)=xe(1,k)+1*exp(1i*((k-1)*(-pi/2)*sind(b(P+i))+((k-1)^2*pi/(16*b(i)))*cosd(b(P+i))^2));
end
end
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
e=norm(xo-xe).^2/(M);

採用された回答

Torsten
Torsten 2023 年 12 月 17 日
編集済み: Torsten 2023 年 12 月 17 日
clear all;clc
u=[3 4 30 50];% Desired Vector
b=u;
[R,C]=size(b);
P=C/2;
M=2*C;
k = (1:M).';
i = (1:P);
xo = sum(1*exp(1i*((k-1).*(-pi/2).*sind(b(P+i))+((k-1).^2.*pi./(16*b(i))).*cosd(b(P+i)).^2)),2)
xo =
2.0000 + 0.0000i 1.1191 - 1.5973i -0.4900 - 1.7093i -1.2963 - 0.6596i -0.9289 + 0.2680i -0.1887 + 0.2713i -0.0020 - 0.4001i -0.5868 - 0.9602i
xe = sum(1*exp(1i*((k-1).*(-pi/2).*sind(b(P+i))+((k-1).^2.*pi./(16*b(i))).*cosd(b(P+i)).^2)),2)
xe =
2.0000 + 0.0000i 1.1191 - 1.5973i -0.4900 - 1.7093i -1.2963 - 0.6596i -0.9289 + 0.2680i -0.1887 + 0.2713i -0.0020 - 0.4001i -0.5868 - 0.9602i
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
e=norm(xo-xe).^2/(M)
e = 0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by