MATLAB: Error when trying to Publish from m file

error

I am having trouble when trying to publish the code below when it is in a m file. Instead of the graph that I expect I get an error message:
Error using evalin Undefined function 'Problem' for input arguments of type 'char'
TempF = 32 : 3.6 : 93.2;
TempC = 5 / 9 * (TempF - 32);
rho = 5.5286 * 10.^-8 * TempC.^3 - 8.5016 * 10.^-6 * TempC.^2 + 6.5622 * 10.^-6 * TempC + 0.99987;
plot(TempC, rho)
xlabel('Temperature in Degrees Celcius')
ylabel('Density of Freshwater (g/cm^3)')

Best Answer

If I enter the following:
%%Water Density vs. Temperature
% This plots the density of freshwater as a function of the temperature
% in celsius.
TempF = 32 : 3.6 : 93.2;
TempC = 5 / 9 * (TempF - 32);
rho = 5.5286 * 10.^-8 * TempC.^3 - 8.5016 * 10.^-6 * TempC.^2 + 6.5622 * 10.^-6 * TempC + 0.99987;
plot(TempC, rho)
xlabel('Temperature in Degrees Celsius')
ylabel('Density of Freshwater (g/cm^3)')
in an M-file called temperature.m and then execute
>>publish temperature.m
or just:
>>publish('temperature')
I have no trouble publishing it.
If you are not actually referring to MATLAB's publish() functionality, but rather using the above as a function, then please be specific.
Related Question