来自工作区数据结构

From Workspace Data Structure

我正在从 Simulink 导入数据,翻转数据,然后尝试使用 Simulink 块导入数据:

from workspace

这总是 return 错误。我试过这个,但它不起作用:

simOut = sim('sim1', Simulation_Time);
t = simOut.P.time;
P_tilde = simOut.P.Data; % size: 2x2x3001
P_data = flip(P_tilde); % size: 2x2x3001, but with the data flipped
P_import = P_data; % import block for 'sim2'
simOut2 = sim('sim2', Simulation_Time);

错误 returned:

Unsupported input format for From Workspace block 'sim2/From Workspace'. Available formats are double non-complex matrix, a structure with or without time, or a structure with MATLAB timeseries as leaf nodes. All formats require the data to be finite (not Inf or NaN).

有人知道如何解决吗?我已经尝试并阅读了“来自工作区”块的描述,但我并不聪明。例如推荐使用的功能; “timeseries(P_data)”或“timetable(P_data)”不起作用,只有 return 个错误。

解决方案有点过于复杂,但它有效。 我翻转 mx 2x2xn 矩阵的每个元素,然后创建一个 timeseries():

simOut = sim('m2_simP', 'StartTime','0','StopTime', num2str(Simulation_Time),'FixedStep',num2str(Time_Step));
t = simOut.P.time;
P_tilde = simOut.P.Data;
p11 = flip(reshape(P_tilde(1,1,:),[],1));
p12 = flip(reshape(P_tilde(1,2,:),[],1));
p22 = flip(reshape(P_tilde(2,2,:),[],1));
for i = 1:size(t,1)
    P_data(1,1,i) = p11(i,1);
    P_data(1,2,i) = p12(i,1);
    P_data(2,1,i) = p12(i,1);
    P_data(2,2,i) = p22(i,1);
end
P_import = timeseries(P_data, t);