Why does this code give an answer for each column seperately?
显示 更早的评论
If you give an input matrix of c = ((rand10,20)>0.5)*2)-1
the code below will give an answer for each column seperately. Why does it do this? shouldn't this code just sum all answers and give a single number?
is it possible to create the same output with nested for loops?
function f = autocorrelation(a)% autocorrelation(a); a: column vector, {-1,+1}
n = length(a(:,1));
for (k=1:1:n-1) % (Start:step:end)
E(k,:) = (sum(a(1:n-k,:) .* (a(1+k:n,:)),1)).^2;
end
f = n^2 ./ (2 * sum(E));
end
1 个评论
Guillaume
2016-10-11
I've formatted your post a bit better. Please remove the # that you added and prevent us from copying your code.
In the future to format text as code click on the {} Code button (or add two spaces before each line)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 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!