Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Is there an error in the code?

4 Ansichten (letzte 30 Tage)
EUNHEI KIM
EUNHEI KIM am 31 Jan. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Day = [19980101];
[DayNumer,Dayname] = weekday(Day,DayForm);
if DayNumber == 7
disp('Take a rest today.')
end
Since 19980101 is saturday, DateNumber 7 is output.
7 has been printed, The 'Take a rest today.' shall be printed out.
However, it is not output.
Is there an error in the code?
Please help me. sir
  2 Kommentare
Alex Mcaulley
Alex Mcaulley am 31 Jan. 2020
There are some typos in your code, but it does what you want (is Saturday and the message is printed)
Day = 19980101;
[DayNumber,Dayname] = weekday(Day);
if DayNumber == 7
disp('Take a rest today.')
end
>> Take a rest today.
EUNHEI KIM
EUNHEI KIM am 31 Jan. 2020
Oh, that was easy.
Thank you very much for letting me know your knowledge. :)

Antworten (1)

Rik
Rik am 31 Jan. 2020
You haven't converted the number to a date yet and you had a typo in your variable name. Also, 1998/01/01 was a Thursday.
Day = 19980101;
DayForm = 'long';
infmt = 'yyyyMMdd';
Day = sprintf('%6d',Day);
Day = datetime(Day,'InputFormat',infmt);
[DayNumber,Dayname] = weekday(Day,DayForm);
if DayNumber == 7
disp('Take a rest today.')
else
disp(Dayname)
end

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by