Finding the cell indices of a cell contains a specific text

3 vues (au cours des 30 derniers jours)
B Janssen
B Janssen le 27 Juin 2017
Hi, I am working with a large CSV file containing blood pressure data (approx 14 million datapoints). I managed to import the data successfully, creating 2 cell arrays (NUMBERS and TEXT). One contains the actual numbers that I want to use for my calculations (NUMBERS), the other (TEXT) contains the information (as a string) about the associated time-points. Since NUMBERS and TEXT run parallel, I can use the cell indices from TEXT, to get to the data in NUMBERS for further computation.
What I am trying to figure out is how to find a specific string in TEXT; e.g. what are the indices of a time point (e.g. 12:00:00)? I started to work with 'strfind' but this only gives me either 0 or 1; not the cell indices that I need. Moreover, the strings in TEXT contain 'Value, Time, Date' (eg. '103.9685,10:27:37,2016-02-03') which means that I only need the middle portion '10:27:37'of the string.
Can anyone provide me with insights/directions as to what strategy/method is best to use in this case?
Thanks! Barry

Réponse acceptée

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH le 27 Juin 2017
I can help you with what you need in this example, it will give you the indices you need :
TEXT={'103.9685,10:27:37,2016-02-03','103.9685,12:00:00,2016-01-03' '103.9685,11:27:37,2016-02-03' '103.9685,12:00:00,2016-02-03' };
indices=find(cell2mat(cellfun(@(x) ~isempty(strfind(x,'12:00:00')),TEXT,'UniformOutput',false)));

Plus de réponses (1)

B Janssen
B Janssen le 28 Juin 2017
Hello Jesus, Thanks for your swift answer. It works! Meanwhile after a strong coffee, I came up with a slightly different solution which also seems to do the trick.
Basically it uses the same example array (TEXT), but subsequently uses an extra step (ARRAY) to find the INDICES:
%
TEXT={'103.9685,10:27:37,2016-02-03','103.9685,12:00:00,2016-01-03' '103.9685,11:27:37,2016-02-03' '103.9685,12:00:00,2016-02-03' };
%
ARRAY = cellfun(@(x)~isempty(strfind(x,'12:00:00')), TEXT);
%
INDICES = find(ARRAY(:) > 0);
The INDICES determine in which row(s) the string(s) can be found. I have timed the code to see which was faster; it turns out that my approach, looking for one string in 14,9915,305 datapoints took 100.15 seconds; while your's took 119.96 seconds. Not exactly sure why this is; but for large data sets a time difference of 20% can be significant.
Again, thanks for your swift and effective response. I hope that combined with my part, others may find this helpful as well!
Barry

Catégories

En savoir plus sur Characters and Strings 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!

Translated by