필터 지우기
필터 지우기

simulink spreadsheet, datetime as duration

조회 수: 9 (최근 30일)
Ultrareidar
Ultrareidar 2023년 2월 27일
댓글: Ultrareidar 2023년 3월 31일
Hi, I have like 5 spreadsheets sampled with different sampling time over a year.
I want to use them in simulink, how can i use a datetime (dd/mm/yyyy hh:mm:ss) as sampling time?

채택된 답변

Nehemiae
Nehemiae 2023년 3월 6일
I will assume an Excel file "Sample Data.xlsx", which has a column named DateTime with time logs for each data sample, in the format (dd/mm/yyyy hh:mm:ss). MATLAB has the datetime datatype that is automatically associated with the table that is read in. Then the duration in seconds between sample points can be calculated as below.
dataTable = readtable("Sample Data.xlsx");
reqDur = dataTable.DateTime(2) - dataTable.DateTime(1); % Replace DateTime with the column name in the Excel file with the time log
reqSec = seconds(reqDur);
Then, "reqSec" can be used in the "Sample Time" property of the "powergui" of Simulink that controls the sample time for discrete simulations in Simulink.
The documentation on datetime (https://www.mathworks.com/help/matlab/ref/datetime.html#d124e321916) can help in understanding the above code.
  댓글 수: 8
Eric Sofen
Eric Sofen 2023년 3월 29일
It's not clear to me whether you want to:
A) bring the data into Simulink at its original logged rate and do aligning (interpolation or sampling) as part of the data ingestion and solving process, or
B) Align the data from the 5 spreadsheets first in MATLAB and then pass it to Simulink.
I think Nehemiae's answers address (A). For (B), you can read the data into timetables and then use the synchronize function to get all the data into a timetable with a 1s timestep.
Ultrareidar
Ultrareidar 2023년 3월 31일
Yes, its has been solved. I added a column to my excel sheet that stored the duration between each sample point, often 15 sec. Then used this line to use it as duration in a timetable : cumsum(duration(0, 0, seconds(dataTable.Duration - dateshift(dataTable.Duration, 'start', 'day'))))
And now i can run with a steptime of 1s.
Thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by