Trying to filter timeseries data by logical index on time within matlab function block but it tells me property Time not recognized as valid
Show older comments
I'm trying to load a year-long timeseries from a .mat file and then select a single day's data from that file within a matlab function block. The loaded timeseries data is one input to the block (tsinput) and a number indicating the day of interest in MMDD format is the other input (daynum). My function block code is:
function tsoutput = fcn(tsinput, daynum)
%find the doy for the daystr input
datestr = strcat(daynum,'2023');
coder.extrinsic('datetime');
datedt = datetime(datestr, 'InputFormat', 'MMddyyyy');
coder.extrinsic('day');
datedoy = day(datedt,'dayofyear');
mask = tsinput.Time>datedoy & tsinput.Time<datedoy+1;
% Create a new timeseries with only those samples
tsoutput = getsamples(tsinput, mask);
But when I try running my simulink code, which is just a from file block and constant number block with the matlab function block, I get these errors:

Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Property 'Time' is not recognized as valid.
Function 'MATLAB Function' (#36.261.273), line 10, column 8:
"tsinput.Time"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of 'testdataload/MATLAB Function'.
Component:MATLAB Function | Category:Coder error
Simulink is unable to determine sizes and/or types of the outputs for block 'testdataload/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink is unable to determine sizes and/or types of the outputs for block 'testdataload/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error in port widths or dimensions. 'Output Port 1' of 'testdataload/MATLAB Function/tsinput' is a one dimensional vector with 1 elements.
Component:Simulink | Category:Model error
Answers (2)
Hi Matthew,
The output signal of the From File block is not a time series, it's probably a double.
The output from the Constant block is not a string, it's probably a double.
The actual types of thse signals can be verified by Debug -> Diagnositics -> Information Overlays -> Ports -> Base Data Types
The output of the From File block is a value from the time series object evaulated at the current simulation time as determined by the "Data extrapolation ...." and "Data interpolation ..." block parameters. It's just a number.
Looks like the Constant block should possibly be changed to a String Constant.
I'm not sure what the path forward could be w/o knowing a bit more about what the Simulink model is supposed to do.
3 Comments
Matthew
on 20 Mar 2026
Walter Roberson
on 20 Mar 2026
From File and From Workspace blocks extract samples by time. By default at any given time they interpolate between stored values; they can instead be configured to "hold" stored values.
The Matlab Function block deals with whatever inputs it receives. The reason the first input to the Matlab Function is a scalar is because a scalar is the output from the From File block, as indicated by the "1" on the signal at the output of that block.
It sounds like you only want to run the code in fcn once at the start of the simulation. If so, there are many ways to do that. Perhaps the easiest is to make sure that the time series (we'll call it tsinput) and the daynum (as a string) are in the base workspace. Then you can use one Constant block and set the "Constant value" parameter to the expression:
fcn(tsinput,daynum).Data
where fcn.m is an m-function file on the Matlab path. fcn.m will execute in base Matlab, so won't need the coder.extrinsic directives (and you can use fcn.m in Matlab independent of Simulink if need be).
Note that the output of fcn is timeseries, but (I don't believe that) Simulink supports timeseries signals, hence we only use the Data portion of the timeseries returned from fcn.
Walter Roberson
on 20 Mar 2026
Moved: Walter Roberson
on 20 Mar 2026
0 votes
It is typically a mistake to think of Simulink of working on discrete chunks of time, such as being able to process one day's worth of entries in a chunk.
It is possible to configure discrete timesteps and to set the timestep to 1 day, but in order to get a day's worth of data extracted from a longer chunk of data, you would need to do something like use a MATLAB Function Block that took the current time as input and which extracted the relevant chunk of data from the file. However, the extracted data would tend to lose its associated time information if you did that. You would need to emit the time as a signal and emit the data chunks as a separate 2D signal, both configured as variable length signals. and you would need blocks that did something with those chunks of signals.
You will not be able to extract a day's worth of data at a time, and process the extracted data in a time-like way.
If you want to process a selected chunk of data in a time-like way, you should probably drive the call to simulink using a MATLAB script or MATLAB function that extracted the data and made it available to simulink (such as From Workspace block.)
2 Comments
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!