Firstly, what's the difference between string and 'string'? One is a variable, the other is a constant string containing 5 lowercase characters. Now why does the function always return 5? Wait, it doesn't return anything because it has no output variable ;)
Mistakes aside, that's a perfectly valid approach assuming we're dealing with purely 7-bit ASCII characters so that "lowercase" implies a single contiguous range. One helpful tip to make the comparisons clearer is to use the characters themselves:
(spoilers)
Lowercase = (string >= 'a') & (string <= 'z');
More generally, since Matlab's handling of non-ASCII characters is locale-specific, in real code (rather than programming exercises) it would be inadvisable to do anything other than let the built-in language methods handle it:
sum(string == lower(string)); or sum(isstrprop(string, 'lower'));