- 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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Wolfgang McCormack
am 18 Jan. 2021
Bearbeitet: dpb
am 18 Jan. 2021
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 Kommentare
Akzeptierte Antwort
dpb
am 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 Kommentare
dpb
am 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?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!