1- Your first mistake is that you cannot call a function in itself. So you must suppress the line [count] = weight(a) after declaring a (a = []).
2- You have an "end" missing for function, which makes it three now.
3- fprintf()for displaying count must be either suppressed or cut and pasted further below. I put it after the loop "for".
4- You must set the counter of the loop "for" to two, then the subscript i-1 set to one.
With all those changes saved, I find 13. Here's the code. I hope it helps:
function [count] = weight(a)
if nargin == 0,
a = [3, 5, 1, -4, 0, 3, 2, 8, -9, 5, 2];
fprintf('Array A is :');
disp(a);
end
[c n] = size(a); %size of a
M = zeros(n);
M(1,:) = 0;
% dynamic code
for i=2:n
M(i) = max(M(i-1)+a(i), a(i));
end
count = M(n);
fprintf('Weight of the maximum consecutive subsequence is %i\n', count);
end