if condition picking certain day of week
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am using a for loop using time as a variable. For day 1 (Monday) there is a value. Then I start a for loop starting from 4th day (Thursday). I want to use for loop only on Day 1(Monday) and Day 4 (Thursday) of every week for 40 weeks. This is related to a situation in radiation treatment where the radiation is given every Monday and Thursday.
I am using following script for 'for loop' which is obviously not true for my above situation. Any help will be appreciated.
Thanks
Dharma
syms x t
c2(x) = 2*dirac(x-1);%day 1
for j=4:4:40 %needs some modification
c2(x) = c2(x)+2*dirac(x-j);
end
0 个评论
回答(1 个)
KSSV
2022-8-3
thedates = (datetime(2022,01,1):datetime(2022,1,31))';
d = day(thedates,'name') ;
idx = ismember(d,{'Monday','Thursday'}) ;
d(idx)
find(idx)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!