How to fix: Attempt to execute SCRIPT fprintf as a function:
Show older comments
This is the script I've put in:
% The program calculates the volume of the water in the water tower.
h=input('Please enter the height of the float in meter ');
if h > 33
disp('ERROR. The hight cannot be larger than 33 m. ')
elseif h < 0
disp('ERROR. The height cannot be a negative number. ')
elseif h <= 19
v = pi*12.5^2*h;
fprintf('The volume of the water is %7.3f, cubic meter.\n',v)
else
rh=12.5+10.5*(h-19)/14;
v=pi*12.5^2*19+pi*(h-19)*(12.5^2+12.5*rh+rh^2)/3;
fprintf('The volume of the water is %7.3f, cubic meter.\n',v)
end
Here's the error msg:
Attempt to execute SCRIPT fprintf as a function:
C:\Users\Holland\Desktop\MatlabExcel\fprintf.m
Error in Problem6Example3 (line 9)
fprintf('The volume of the water is %7.3f, cubic meter.\n',v)
*I've struggled on this for a few hours now, any help would be much appreciated.*
Answers (3)
Fangjun Jiang
on 22 Aug 2016
1 vote
fprintf() is a built-in function. \toolbox\matlab\iofun\fprintf.m is a help text file.
Why do you have your own C:\Users\Holland\Desktop\MatlabExcel\fprintf.m file?
It sounds like your fprintf.m is an M-script (without function keyword at the first line) but you are trying to use it as a function.
Holland Mills
on 22 Aug 2016
0 votes
Holland Mills
on 22 Aug 2016
0 votes
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!