Im trying to reformat a time vector to only use the seconds. For example the data was recorded using the actual time in 20 second intervals: 11:06:30 11:06:50 11:07:10 the only thing that is relevant to me are the seconds. How do I adjust this without having to do it manually?

6 commentaires

Tim Fensterer
Tim Fensterer le 15 Oct 2017
i was thinking about trying to use the erase function to delete the substrings but i wasn't sure how to manage the fact that the "minutes" are changing
KL
KL le 15 Oct 2017
How do you store these values?
Tim Fensterer
Tim Fensterer le 15 Oct 2017
they are stored as a column vector "Sample Time
" 11:06:10 11:06:30 11:06:50 11:07:10 11:07:30 11:07:50 11:08:10 11:08:30 11:08:50 11:09:10 11:09:30 11:09:50 11:10:10 11:10:30 11:10:50 11:11:10 11:11:30 11:11:50 11:12:10 11:12:30 11:12:50 11:13:10 11:13:30 11:13:50 11:14:10 11:14:30 11:14:50 11:15:10 11:15:30 11:15:50 11:16:10 11:16:30 11:16:50 11:17:10 11:17:30 11:17:50 11:18:10 11:18:30 11:18:50 11:19:10 11:19:30 11:19:50 11:20:10 11:20:30 11:20:50 11:21:10 11:21:30 11:21:50 11:22:10 11:22:30 11:22:50 11:23:10 11:23:30 11:23:50 11:24:10 11:24:30 11:24:50 11:25:10 11:25:30 11:25:50 11:26:10 11:26:30 11:26:50 11:27:10 11:27:30 11:27:50 11:28:10 11:28:30 11:28:50 11:29:10 11:29:30 11:29:50 11:30:10 11:30:52 11:31:12 11:31:32 11:31:52 11:32:12 11:32:32 11:32:52 11:33:12 11:33:32 11:33:52 11:34:12 11:34:32 11:34:52 11:35:12 11:35:32 11:35:52 11:36:12 11:36:32 11:36:52 11:37:12 11:37:32 11:37:52 11:38:12 11:38:32 11:38:52 11:39:12 11:39:32 11:39:52 11:40:12 11:40:32 11:40:52 11:41:12 11:41:32 11:41:52 11:42:12 11:42:32 11:42:52 11:43:12 11:43:32 11:43:52 11:44:12 11:44:32 11:44:52 11:45:12 11:45:32 11:45:52 11:46:12 11:46:32 11:46:52 11:47:12
Tim Fensterer
Tim Fensterer le 15 Oct 2017
not sure if this answers your question, I'm relatively new to Matlab / coding in general. I imported the data from an excel file generated by the lab equipment's software package.
Tim Fensterer
Tim Fensterer le 15 Oct 2017
Also, if you look at the data above, you can see at 11:30:10 it jumps to 11:30:52, then continues on in 20 second intervals. this is because we stopped the system and then turned it back on
berenice va-t-on
berenice va-t-on le 15 Oct 2017
clear X for i=1:size(Crop,3), X(:,i)=reshape(Crop(:,:,i),[10000 1]); end
averageFace=mean(X')';
A=double(X)-repmat(averageFace,[1 size(Crop,3)]);
[U,S,D]=svds(A, 30);
lTFaces=(U(:,1:20)')*(double(X)-repmat(averageFace,[1 size(Crop,3)])); UnknownFace=imread('47-1.JPG.jpg'); imagesc(UnknownFace) UnknownCrop=extract_face(rgb2gray(UnknownFace),100); close lUnknownFace=(U(:,1:20)')*(double(reshape(UnknownCrop,[10000 1]))-averageFace); EuclideanDist=sqrt(sum((lTFaces-repmat(lUnknownFace,[1 size(lTFaces,2)])).^2)); [match_score, match]=min(EuclideanDist) imagesc(reshape(X(:,match),[100 100])); colormap(gray); axis image
filenames=dir; for i=3:48, files{i-2}=filenames(i).name; dates{i-2}=filenames(i).date; end [ignore,idx]=sort(dates); sortedfiles=files(idx);

Connectez-vous pour commenter.

 Réponse acceptée

KL
KL le 15 Oct 2017
Modifié(e) : KL le 15 Oct 2017
One idea is to store them as datetime and then extract just seonds field, for example
dt = datetime('11:06:20');
secOnly = dt.Second
This should only give you the 20. You could do this for your whole range to store as a vector.

4 commentaires

Tim Fensterer
Tim Fensterer le 15 Oct 2017
Ok sounds good, How would i go about applying that to the entire vector? would i say something like (assuming the data above has the variable name 'sampletimefin') dt = datetime('sampletimefin') seconly = dt.Second
KL
KL le 15 Oct 2017
Modifié(e) : KL le 15 Oct 2017
The data you import from your excel file should be the input vector in this case. Suppose your vector, after importing, looks like this,
sampletimefin = ['11:06:10'; '11:06:30';'11:06:50'] %these are dummy data just to show you how it should look like
dt = datetime(sampletimefin)
secVec = dt.Second
Tim Fensterer
Tim Fensterer le 15 Oct 2017
Awesome, that worked. thanks KL! If I were to decide to include the minutes as well, is the there a "dt." function for that too? I really appreciate your advice.
Yes, just
dt.Minute
and so on. You can read more on this below link https://de.mathworks.com/help/matlab/ref/datetime.html#d119e193213 .

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 15 Oct 2017
Modifié(e) : Andrei Bobrov le 15 Oct 2017
c = readtable('20171015.txt','delimiter',':','ReadVariableNames',false)
t = duration(c{:,:})
out = seconds(t);

Catégories

En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by