I would use numel(ind) instead of size(ind, 2), since ind is a vector.
As for your question, the first word is the content of Str up to the first space ( ind(1)-1) and the last is the content of Str from the last space( ind(end)+1), so:
firstword = Str(1:ind(1)-1);
lastword = Str(ind(end)+1:end);
Best Answer