This solved it for me:
delete temp.txt
diary temp.txt
for i= 1:length(vector)
X = sprintf('vector(%d)=',i);
disp(X)
vector(i)
end
diary off
%%
find_and_replace('temp.txt', '\n \nans =\n \n', ' ');
find_and_replace('temp.txt', '\n \n', ';\n \n');