Hello I am new to Matlab.
I have been trying to increment a 1 by 3 matrice (basically time in Hh:mm:Ss.sss) by 30 seconds, n number of times. What's the best way to do this?
Thank you!

댓글 수: 4

KALYAN ACHARJYA
KALYAN ACHARJYA 2017년 9월 11일
I am not getting your question. Though its answer seems simple, please clarify.
the cyclist
the cyclist 2017년 9월 11일
Please give an example of your matrix. There are a few ways to store a date/time value in MATLAB.
Andrew Dicom
Andrew Dicom 2017년 9월 11일
Sorry :/ It's basically something like this e.g [15 25 01] I want to to increment it by 30 seconds for 180 times.
So the output will look like this:
15 25 01
15 25 31
15 26 01
Etc...
I know it probably sounds simple but it's one of my first time using this program...
I'm using R2012a so datetime can't really function here and I've tried installing it but it still seems not to work... Is there another way?
Thank you and sorry if it sounds like a juvenile question.
Image Analyst
Image Analyst 2017년 9월 11일
편집: Image Analyst 2017년 9월 11일
Don't do it like that. Use official time variables instead of trying to keep track of all the parts of time yourself. It will be so much easier. See answer below for one way.

댓글을 달려면 로그인하십시오.

 채택된 답변

KL
KL 2017년 9월 11일

2 개 추천

start_t = datenum('15:25:01','HH:MM:SS')
step_t = datenum('15:25:31','HH:MM:SS')-datenum('15:25:01','HH:MM:SS');
end_t = datenum('16:55:01','HH:MM:SS')
ts = start_t:step_t:end_t;
ts_dvec = datevec(ts);

댓글 수: 5

Andrew Dicom
Andrew Dicom 2017년 9월 11일
Hello. Thank you so much for the reply. Will this work if I wanted to replicate it to produce 200 number of 30 second increments as well?
KL
KL 2017년 9월 12일
Yes, you should just change the end time ( end_t).
Hello KL, Thank you so much for the reply! The script works great and helped a lot. In the script you wrote, I'll have to manually key in the HH:MM:SS each time I run. But what if I wanted it to read it from a few hundred .mat files like the following:
load('ACT2007-sh.mat')
M = D.other.info.hour;
%M = 15:25:01 (example only, value may vary depending on .mat file)in HH:MM:SS;
I want to create 180 epochs of 30seconds for M I will be repeating this process with multiple .mat files so it would not be ideal to calculate the final epoch for n=180 for each one.
KL
KL 2017년 9월 12일
your_folder = 'YOUR_FOLDER_PATH'; %folder where mat files are there
folderInfo = dir([your_folder '/*.mat']);
fnames = {folderInfo.name};
n = 180; %your count
for iFile=1:numel(fnames)
S = load(fullfile(your_folder,fnames{iFile}));
starttime = S.yourvarname; %must be a text in 'HH:MM:SS' format
start_t = datenum(starttime,'HH:MM:SS');
step_t = 3.47222e-4;
end_t = start_t+(step_t*n);
ts = start_t:step_t:end_t1;
%%do whatever you want
end
Andrew Dicom
Andrew Dicom 2017년 9월 13일
thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2017년 9월 11일

댓글:

2017년 9월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by