How to filter data from a timetable based on a string value?
7 views (last 30 days)
Show older comments
Hi all,
I am trying to filter a timetable by only selecting data that contain a desired string value in the second column.
My timetable has 3 columns in total: dates, assets, scores (but the dates column is not numbered, so I think Matlab perceives the timetable as having 2 non-time/date columns).
There are many types of assets under my "assets" column but I only want to select data that have "fixedinc" as their asset names.
Could you please tell me which code I should use?
I am completely new to matlab and this part has been a bottleneck.
Thank you!
0 Comments
Accepted Answer
dpb
on 5 Jun 2019
Probably something like
isfixed=contains(tt.assets,'fixedinc'); % if string or cell string, should locate
tt(isfixed,:) % will display what was selected
Likely the assets data could effectively be a categorical variable--
tt.assets=categorical(tt.assets); % convert to categorical type
isfixed=(tt.assets=='fixedinc'); % the logical index array w/ categorical type
tt above is, of course, the timetable--use whatever you named yours in place.
Above is purely speculative on the assumption of what the timetable variables actually are which you've not given any real informtion on.
1 Comment
More Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!