i have a input problem.Cannot call INPUT from EVALC. in my code

7 次查看(过去 30 天)
hello this message appear when i try tu publish my program Error using input * Cannot call INPUT from EVALC. Error in hw1 (line 4) year= input('Enter the year (yyyy)\n:'); *
my code is the following:
year= input('Enter the year (yyyy)\n:');
month=input('Enter the month: ');
day=input('Enter the day: ');
fprintf('\nYou entered %3.0f/%2.0f/%4.0f',month,day,year)
d=day;
m=month-2;
if m<=0
m=m+12;
year=year-1;
endy=mod(year,100); % year's number in the century
c=(year-y)/100; % number of centuries
%formula input
%weekday= mod((d+((1/5)*(13*m-1))+y+(y/4)+(c/4)-2*c+777),7);
%week={'Sunday' 'Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday'...'Saturday'};
%fprintf('\n\nYour weekday is: %s\n', week{weekday+1}); % result
%Subscript indices must either be real positive integers or logicals.
weekday= mod((d+fix((1/5)*(13*m-1))+y+fix(y/4)+fix(c/4)-2*c+777),7);
week={'Sunday' 'Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday'...
'Saturday'};
fprintf('\n\nYour weekday is: %s\n', week{weekday+1}); % result
can anyone help me?

回答(2 个)

Geoff Hayes
Geoff Hayes 2014-10-4
Alejandro - I copied your file and opened it in the MATLAB editor. On the Publish tab, I pressed the Publish button and observed the same error as you. The same error occurs if you run the following in the Command Window
publish('myScript.m')
This is because the default setting for the publish functionality is to evaluate the code. If you wish to disable this setting, in the editor on the Publish tab, press the down arrow on the Publish button and select Edit Publishing Options. In the Code Settings section change the Evaluate Code from true to false, and press Publish. The resulting HTML (or whatever you have selected as output) should no longer display this error.
If publishing from the command line, just disable the evaluation of your script/program as
publish('myScript.m','evalCode',false)
  4 个评论
lal popat
lal popat 2018-8-28
This is just avoiding execution of the code. What if I want to run the same using some temp inputs? Like executing the script with input of year, month etc
Steven Lord
Steven Lord 2018-8-28
Separate the interface and the computation pieces.
  • Write a script file that uses input to prompt the user for values for the parameters. This is the interface piece.
  • Write a function file that accepts the parameters as input arguments. This is the computational piece.
When you want to perform the computations interactively call the script and have it call the function directly, specifying the values the script received from the user as the inputs to the function.
When you want to perform the computations non-interactively (such as when you want to publish your results) just call the computational function directly and specify the input arguments in that function call.

请先登录,再进行评论。


Gabriela
Gabriela 2023-6-15
clc
clear
disp('This program will calculate the time in which the crime was committed')
To=input('Enter the temperature upon arrival.To= '); %temperature in Farenheit
Ts=input('Enter the temperature of the room.Ts= '); %temperature in Farenheit
T=input('Enter the temperature after one hour after the scene.T= '); %temperature in Farenheit
%t= 1 unit in hours
k=-log((T-Ts)./(To-Ts));
NT=input('Enter the normal temperature of the body.NT= '); %temperature in Farenheit
t=-(1/k)*log((T-Ts)./(NT-Ts)); %time in hours fprintf('\nThe time at which the crime was commited was %.2f hours before they arrived\n',t) This program will calculate the time in which the crime was committed
Gave me teh same error. But I do what it says in the instructions and it keep giving me the same error.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by