Finding values on only time (excluding date)

6 visualizzazioni (ultimi 30 giorni)
sikander shahzad
sikander shahzad il 5 Ott 2017
Commentato: Cam Salzberger il 6 Ott 2017
  3 Commenti
sikander shahzad
sikander shahzad il 5 Ott 2017
Each column is stored in separated variable.
sikander shahzad
sikander shahzad il 6 Ott 2017
variables are value1 (6 x 1) double, value2 (6 x 1) and value3 (6 x 1). whereas date/time is (6 x 1) cell array.

Accedi per commentare.

Risposte (2)

Cam Salzberger
Cam Salzberger il 5 Ott 2017
Hello Sikander,
If you can import your data and get it into a datetime format - readtable is good for this - then this is pretty easy. Just use timeofday to drop the date portion of the datetime.
-Cam

Andrei Bobrov
Andrei Bobrov il 5 Ott 2017
T = readtable('data1.xlsx');
T.Date_Time = datetime(join(string(T{:,1:2})),'I','dd-MM-uuuu HH:mm');
T = T(:,[1,3:end]);
out = T(hour(T{:,1}) == 8,:);
  2 Commenti
sikander shahzad
sikander shahzad il 6 Ott 2017
I have data with many row. kindly show me the way to use find function and with the help of index i can fetch required result.
Cam Salzberger
Cam Salzberger il 6 Ott 2017
You generally shouldn't need to use the "find" function. It is often more efficient to just use logical indexing directly. That is what is being done with Andrei's example. The expression:
logicalArray = hour(T{:, 1}) == 8;
will produce a logical array of the same number of rows as T, with "true" whenever the hour value in the first column of T is 8. When you do:
T(logicalArray, :)
it will return only those rows that were "true" in the logical array.
-Cam

Accedi per commentare.

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by