Simulink ToWorkspace block generates timeseries with incorrect data dimensions.

23 次查看(过去 30 天)
I have a large simulink model with multiple ToWorkspace blocks in it. For some reason, some of the timeseries generated have a data dimension of nxm where the data dimension at time t is m and the dimension of the time vector is n. Seems to me that the last data dimension should correspond to the length of the time vector. All the multidimensional timeseries generated are the expected pxmxn with the time vector of length n. Not all of the 1 dimensional timeseries are incorrect. The settings for all the ToWorkspace blocks are the same. Very frustrating as I need to do complicated time analyses and the incorrect data dimensions keep breaking things.
I'm using 2013b.

采纳的回答

Chinmayi Lanka
Chinmayi Lanka 2016-11-22
The "To Workspace" block creates a timeseries with Data of size Nx1 when passed scalar signals and Data of size AxBxN for signals of size AxB.
When defining the elements of a bus in the Bus Editor you can specify the dimensions of each element. If the "Dimensions" field of a BusElement is set to 1, the output of a Bus Selector block for that element will be a normal scalar signal and will give an Nx1 matrix when exporting with the "To Workspace" block. However, if the "Dimensions" field is set to [1 1] the "To Workspace" block treats the signal like a two-dimensional signal and concatenates values from different time steps along the third dimension, which results in a 1x1xN variable exported to the workspace.
Assigning the dimensions of a Signal to [1 1] can cause Simulink to treat the signal as a 2D matrix. This can be demonstrated by connecting a Constant block, Signal Specification block, and To Workspace block together and setting the dimension to [1 1] in the Signal specification block.
To ensure consistent dimensions make sure all of your scalar bus elements that might affect the signal passed into the "To Workspace" block have their "Dimensions" field set to [1 1] and not 1 or set relevant Signal dimensions to [1 1] instead of 1.

更多回答(2 个)

Ian Dougherty
Ian Dougherty 2016-11-22
编辑:Ian Dougherty 2016-11-22
Thanks for the reply. Seems inconsistent to me to have the data dimension corresponding to the time index to be in different places depending on the type of data recorded. Would make things easier if the last dimension of the data vector always corresponded to the time index. For anyone having this problem, I solved it by creating a subclass that inherits from the timeseries object class and wrote the constructor like:
function obj = NewTimeSeries(varargin)
if length(varargin) == 1 && isa(varargin{1}, 'timeseries')
dSize = size(varargin{1}.Data);
tLen = length(varargin{1}.Time);
if dSize(1) == tLen && dSize(end) ~= tLen
varargin{1}.Data = shiftdim(varargin{1}.Data', -1);
end
end
obj = obj@timeseries(varargin{:});
end
Then I just convert all timeseries object from the simulation output to the new version by:
newTimeSeries = NewTimeSeries(oldTimeSeries);

Vishal Chouhan
Vishal Chouhan 2019-11-23
Normally, when i choose timeseries in "to workspace" block to collect my data from my simulink model, but this time i used it i got nothing but a empty struct in my workspace, simulation run for 124sec simulation time (discrete 1e*(-05)), is there any data storage limitation in timeseries (to workspace)? i dont know what happend ,my simulation took 5 hour to simulate my model,

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by