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!
