If you click the little drop-down menu next to the publish button, you'll see an item called Edit Publish Configurations. If you select that (while the file you want to publish is open in the editor), you'll see you have a MATLAB expression that you can edit. This is the MATLAB code that gets executed when you publish the script, and by default it's just the name of your script.
Let's say your script is called myscript, so by default the published expression is just
myscript
You can edit the expression to be:
userinput = 'example';
myscript
Then this will be run when you hit the publish button.
Within your script, change the line
userinput = input('Enter the code here\n', 's');
to
if ~exist('userinput', 'var')
userinput = input('Enter the code here\n', 's');
end
Now your script will run as normal (assuming you don't have a variable 'userinput' in the workspace), and your script will publish successfully.
Hope that helps!
publish(mfilename). Only scripts may be published.