- Import the data with readtable or since you do have dates, optionally readtimetable
- See weekday combined with
- logical indexing; one of the most powerful features in MATLAB and one must learn to use to be effective.
How to separate weekends from weekdays from an Excel file in MATLAB?
1 次查看(过去 30 天)
显示 更早的评论
Hi Everone,
I have an Excel file like this:
(the date is like a text file)
Column 1 Column 2 Column 3
2020-04-02-thursday 45 67
2020-04-03-friday 33 88
....
How can I seperate the weekends and weekdays and write them to two seperate files in MATLAB?
Also, how can I extract a range from these days? For example, extract the days that their column 2 has value above 60?
Also, another question, how can I say, multiply cells that have a value above 50 by 2 in columns2 and multiply cells that have a value betwenn 20 and 30 by 0.5 in column 2.
Thank you so much. I am a novice in MATLAB so I would really appreciate it if you could help me!
0 个评论
采纳的回答
dpb
2021-1-18
Well, ya' gotsa' start somewhere! We all were newbies once...give it a shot and see how far you get on your own first...
All of the above is pretty simple and straightforward but you'll learn MATLAB faster by trying than just taking code somebody else hands you.
The outline of the above would be something like
t=readtimetable('ExcelFile.xlsx');
isWeekEnd=beginsWith(t.Date,'S','ignorecase',1); % logical vector if day starts with S|s
tWE=t(isWeekEnd,:); % the WE only table all columns
ix=t.Var2>50; % logical vector Var2 > 50
t.Var2(ix)=2*t.Var2(ix); % multiply those by 2
As can see, it's all pretty obvious when see it...there are examples of all this syntax in the "getting started" section in the doc or examples for the various functions.
6 个评论
dpb
2021-1-18
Well, I'm not sure about how to do that with timerange as I've not used it enough to be fully familiar with the optional use of durations and the 'unitOfTime' time periods to be able to do this internally to it or not. The examples are of some help but do not always explore all the nuances that are possible.
However, there was this link to what appears to be the same question on the Answers page <How-to-filter-rows-in-a-timetable-based-on-a-range-between-08-00-and-16-00-for-everyday> that appears to address the Q?
更多回答(0 个)
另请参阅
类别
在 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!