How do I do this summation equation in MATLAB
조회 수: 7 (최근 30일)
이전 댓글 표시
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1380734/image.png)
where u is a pair
and
is a 128x128 matrix
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1380739/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1380744/image.png)
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
댓글 수: 0
채택된 답변
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
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=vecnorm(Y(:,1:N/2),2,2).^2/N;
eta
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!