- 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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
dpb
le 18 Jan 2021
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 commentaires
dpb
le 18 Jan 2021
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?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!