Variable sample time with different time values
이전 댓글 표시
Hello,
i have the following data,for example and a simulation duration in simulink for 2 seconds.
Time Parameter
0 4
0.7 8
1.14 10
2 7
With a From Workspace Block i transfer the time and parameter data to simulink. With a To Workspace Block i transfer the results to matlab workspace.
Which setting do i have to change in simulink or how do i set the sample time in the To Workspace Block
that i got four results for 0,0.7,1.14 and 2 seconds to the matlab workspace?
Regards,
Philipp
댓글 수: 4
Mathieu NOE
2021년 1월 11일
hello
you mean 5 results for 0,0.7,1.14 and 2 seconds ?
you can use in matlab interp1 to gerate the missing 5th value for parameter
Philipp Vogel
2021년 1월 11일
Mathieu NOE
2021년 1월 12일
hello
my first idea would be to make the simulink (fixed) steps = 0.02 (because then you can "pick" the data with time index whatever time value as soon as they are multiples of 0.02 , which is the case for the time values you are looking for)
simulink time simulation must be set from 0 to 2 s.
of course the array generated by simulink will have more values than needed , but you simply have to add in your script that you want only those values : see example below (tested with dummy data - to be replaced by your simulink array)
time = 0:0.02:2; % dummy data
data = (1:length(time))*5; % dummy data
tt = [0,0.7,1.14,2]; % time values for data retrieval
idx = ismembertol(time(:), tt(:));
c = 1:length(time);
d = c(idx) % searched time indexes
extracted_data = data(d)
Philipp Vogel
2021년 1월 14일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Sources에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
