Weekend extraction in Matlab

◇◆丶佛笑我妖孽 提交于 2019-12-02 08:46:51
rayryeng

We can find which elements in the weekday function fall on a weekend by checking to see if the first column of your matrix when inputted into this function outputs a 1 or a 7. Once we do this, this will give us which rows we can select out from timeVectorDaily.

Without further ado:

arrayAllDay = weekday(timeVectorDaily(:,1));
loc = arrayAllDay == 1 | arrayAllDay == 7;
weekendRows = timeVectorDaily(loc,:);

arrayAllDay contains numbers from 1 to 7 that tell you what day of the week that number falls on. loc is a logical array where 1 denotes that the day falls on a weekend and 0 where it doesn't. Finally, weekendRows will contain all rows that correspond to weekends. As such, this will produce a M x 5 matrix, where M are the total amount of weekends that correspond to the first column of your matrix.

BTW, referring to @Shai, it is inadvisable that you use i and j as iteration variables as these are used for representing complex numbers. See this link here: Using i and j as variables in Matlab . Doing so will shadow over these complex variables, and if you do any complex analysis later on, you may get unpredictable results.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!