Using Input Function and Logic to Complete a Task

As a part of a project, I am trying to use the input function to enter a day of the week and if said day is on the weekend it results in one output dialogue, if it is a weekday it is a separate output dialogue. Any help on how to format this correctly? I'll put what I currently have below.
% Day of week using the input function
clear
clc
day_of_week = input('What is your favorite day of the week? \n','s');
if (day_of_week == Saturday || day_of_week == Sunday );
disp('Have a nice weekend!')
else
disp('Good luck in your class lectures and studies.');
end

回答 (1 件)

Star Strider
Star Strider 2019 年 10 月 26 日

0 投票

First, the weekday function could make this much easier, depending on what you want to do.
Second, if you choose the string output from weekday (or just generic strings), use the strcmp function to compare the strings.
(I personally prefer intputdlg to input. You could also use listdlg.)
That should get you started.

カテゴリ

ヘルプ センター および File Exchange で Dates and Time についてさらに検索

製品

質問済み:

2019 年 10 月 26 日

回答済み:

2019 年 10 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by