Trying to filter timeseries data by logical index on time within matlab function block but it tells me property Time not recognized as valid

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

3 Comments

Set a breakpoint in the MATLAB code and show us what
whos
returns first.
It won't run even with a breakpoint at the very beginning of the matlab function block code - I'm guessing my errors are compile errors?
The matlab code works perfectly fine in matlab environment.
That's on the interface side to Simulink, then...I dunno anything about that side, sorry.

Sign in to comment.

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

So it looks like the Matlab Function block just deals with one data point at a time, as loaded with the From File block?
I tried an even simpler version (no logical indexing) and it looks like the input to the Matlab Function block is a single value - whenever I tried to manually index with a value greater than 1, I got an error saying the length of the variable I was trying to index was 1.
If that's the case can you do any data input filtering in simulink at all? I'd like to be able to use a different day of year's data for my model simulation and be able to select the day of interest via an input (string or double) in simulink. But I don't see how that's possible if single values instead of arrays are being passed on.
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.

Sign in to comment.

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

I understand - I'm not really looking to send all the data as a chunk - if it's only going into the model one element at a time that's fine, but I do want those elements limited to a subset of a file read in via the From File block and I'd also like the subset start/end points to be limited via input to the model.
By playing around with things a bit, I can manually limit the end-point of the read data by adjusting model stop time. I'm trying to figure out if I can then adjust the start=point by using the From File block's sample time, but it looks like the offset part of that input can't be more than the sample time itself?
So I think the way to go is do all data subset filtering in matlab, then save my subset timeseries dat as well as stop time and solver fixed-step size as variables.
Then load everything using From Workstpace in Simulink and call simulink from same matlab script that created/saved the variables.
That seems to work the way I want - just an extra step creasing/saving variables and running simulink file from within, but all do-able.

Sign in to comment.

Products

Release

R2025b

Asked:

on 20 Mar 2026

Edited:

on 23 Mar 2026

Community Treasure Hunt

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

Start Hunting!