How to change values in a vector

2 Ansichten (letzte 30 Tage)
Tim Fensterer
Tim Fensterer am 15 Okt. 2017
Kommentiert: berenice va-t-on am 15 Okt. 2017
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 Kommentare
Tim Fensterer
Tim Fensterer am 15 Okt. 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 am 15 Okt. 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);

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KL
KL am 15 Okt. 2017
Bearbeitet: KL am 15 Okt. 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 Kommentare
Tim Fensterer
Tim Fensterer am 15 Okt. 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.
KL
KL am 15 Okt. 2017
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 .

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 15 Okt. 2017
Bearbeitet: Andrei Bobrov am 15 Okt. 2017
c = readtable('20171015.txt','delimiter',':','ReadVariableNames',false)
t = duration(c{:,:})
out = seconds(t);

Kategorien

Mehr zu Data Type Identification 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!

Translated by