How do I do this summation equation in MATLAB

1 回表示 (過去 30 日間)
Brian
Brian 2023 年 5 月 11 日
コメント済み: Torsten 2023 年 5 月 12 日
Hi! I'm a beginner MATLAB user and I'm trying to implement this summation equation in MATLAB but I'm not really sure how?
I'm used to other programming languages so I'd likely just use a nested for loop but I'm not sure if that's the best approach with MATLAB.
Equation is here:
where u is a pair and is a 128x128 matrix
My current best guess is to use nested for loops as such:
eta = zeros(1, N); % 1xN column vector to store answer
for row = 1:N %u1 is a "row"
tmp = 0;
for col = 1:N/2 % u2 is the "column" and only goes to N/2 (specified elsewhere)
tmp = tmp + abs(Y(row, col))^2;
end
eta(1, row) = tmp / N;
end

採用された回答

Matt J
Matt J 2023 年 5 月 11 日
編集済み: Matt J 2023 年 5 月 11 日
Looks like you could simply do it in one line with,
eta=vecnorm(Y(:,1:N/2),2,2).^2/N ;
  2 件のコメント
Brian
Brian 2023 年 5 月 11 日
Is that effectively the same as the way I have it done currently? Just more succint?
Torsten
Torsten 2023 年 5 月 12 日
N = 4;
Y = rand(N) + 1i*rand(N);
eta = zeros(1, N); % 1xN column vector to store answer
for row = 1:N %u1 is a "row"
tmp = 0;
for col = 1:N/2 % u2 is the "column" and only goes to N/2 (specified elsewhere)
tmp = tmp + abs(Y(row, col))^2;
end
eta(1, row) = tmp / N;
end
eta
eta = 1×4
0.0859 0.2986 0.3841 0.3292
eta=vecnorm(Y(:,1:N/2),2,2).^2/N;
eta
eta = 4×1
0.0859 0.2986 0.3841 0.3292

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by