I am importing data from Simulink, flip the data and then try to import the data with the Simulink block:
from workspace
This always returns a error. I tried this, but it doesn't work:
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);
The error 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).
Does anyone has a idea how to solve it? I have tried and read the description for the "from workspace" block, but I am not any smarter. For example, the functions recommended to use; "timeseries(P_data)" or "timetable(P_data)" do not work and just return errors.
CodePudding user response:
The solution is little bit too complicated, but it works. I flip each element of mx 2x2xn matrix, then I create a 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);