Can't understand this MATLAB syntax?
2 answers
p = (0:255)'; m = zeros(1,256); for i=0:255 m(i+1)=sum((0:i)'.*p(1:i+1)); end
m[i+1]
contains a dot product [0,1,2,..,i]
with(p[1],...,p[i+1])
You can write it like:
p = (0:255);
m = zeros(1,256);
for i=0:255
m(i+1)=sum((0:i).*p(1:i+1));
end
Or:
p = (0:255); m = zeros(1,256); for i=0:255 m(i+1)=(0:i)*p(1:i+1)'; end
If you don't remember, this is the definition of a scalar product
+4
source to share