Matlab 计算一年中第n天的代码

Matlab 计算一年中第n天的代码,matlab,Matlab,我想写一个matlab代码,得到哪一天是一年中的第一天,也得到n,并显示哪一天是那一年的第n天。 我也不知道为什么它不能比较sat和wi的例子 W=[周六、周日、周五] 请帮帮我,我真的做不到 这就是我到目前为止所做的: First=input('sat,sun,...,fri'); day=('a number between 1and 365'); day=mod(day,7); w=[sat,sun,....,fri]; for i=1:7 if first==w(i)

我想写一个matlab代码,得到哪一天是一年中的第一天,也得到n,并显示哪一天是那一年的第n天。 我也不知道为什么它不能比较sat和wi的例子 W=[周六、周日、周五] 请帮帮我,我真的做不到

这就是我到目前为止所做的:

First=input('sat,sun,...,fri');
day=('a number between 1and 365');
day=mod(day,7);
w=[sat,sun,....,fri];
for i=1:7
    if first==w(i)
        disp(mod(i+day,7))
    end
end

注意下面代码中的语法。我注意到你的语法有很多错误。另外,我建议您使用datenumand datestr,如下代码所示。运行help datenum和help datestr以获取有关函数的更多信息

% User selects a year as a double
year = input('Select a year: '); 

% the first day of that year as a value
date = datenum([num2str(year),'-01-01']); 

% Get the name of the first day and diplay it
first = datestr(date,'dddd'); 
disp(['The first day of ', num2str(year), ' was a ', first])

% get nth day from user
day = input('Choose a number between 1 and 365: '); 

% Add this value to the value of 1st jan on the selected year
newDate = date + day-1; 

% Turn this date into a string and display it
nth = datestr(newDate,'dddd-dd-mmmm'); 
disp(['Day ', num2str(day),' of ', num2str(year), ' was ', nth])

第一个=输入'sat,sun,…,fri';day='1和365'之间的数字;day=modday,7;w=[周六、周日、周五];对于i=1:7,如果first==wi dispmodi+day,则7结束用代码编辑您的问题。请不要把它贴在墙上comments@user297564,如果答案正确,请接受。