Info
此问题已关闭。 请重新打开它进行编辑或回答。
Summation issue using loop
1 次查看(过去 30 天)
显示 更早的评论
I am trying to implement this summation in matlab but i do not know how ?
thank u

1 个评论
回答(2 个)
Robert U
2019-10-20
Hi Ali aaa,
in your code parts are missing. Without knowing any constraints about the variables, I suggest the following solution:
- Define a (local) function to solve the summation formula
- check input validity
- Try to vectorize the calculation
function [Em] = sum_mNi(x,m,N)
validateattributes(x,{'numeric'},{'vector','nonempty'});
validateattributes(m,{'numeric'},{'scalar','nonempty'});
validateattributes(N,{'numeric'},{'scalar','nonempty'});
Em = 1/N * sum(cell2mat(arrayfun(@(ind) x.^2 .* (m*N + ind),0:N-1,'UniformOutput',false)'),1);
end
The solution might be wrong, depending on the input value types.
Kind regards,
Robert
0 个评论
此问题已关闭。
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!