l2norm = 0.0; total = 0.0; for i = 1:length(pgl) l2norm = l2norm + (pgl(i)-pgh((i-1)*2+1))^2.0 ; total = total + pgh((i-1)*2+1)^2.0; index must not exceed 46. in matlab
You can add an if statement to stop the loop when i reaches the value of 46 as follows:
main.m
l2norm = 0.0;
total = 0.0;
fori = 1:length(pgl)
ifi > 46breakend l2norm = l2norm + (pgl(i)-pgh((i-1)*2+1))^2.0 ;
total = total + pgh((i-1)*2+1)^2.0;
end
190 chars
10 lines
This will break the loop when the value of i is greater than 46.