If the ‘u’ and ‘y’ data are in the time domain, use the iddata function to create a data object that the estimation functions (such as tfest and ssest) can use to estimate the system. (Then use the compare function to visually explore the fit.)
The only absolute requirement is that ‘u’ and ‘y’ exist in the workspace that uses them and that they are the same size and are appropriate for the model being estimated. If they exist in a .mat file, they first need to be loaded into the workspace, however they do not have to start out in a .mat file, although they are usually read in from a .txt or Excel file simply because that is what the instrumentation that acquires the data writes them to.
EDIT — (4 Feb 2022 at 12:18)
Added this:
Example —
t = linspace(0, 10, 250);
u = [0 1 zeros(1, numel(t)-2)];
y = exp(-0.2*t) .* sin(2*pi*t) + randn(size(t))*0.1;
Ts = t(2)-t(1);
data = iddata(y(:), u(:), Ts) % Arguments Must Be Column Vectors Or Scalars
sys = tfest(data, 2)
figure
compare(data, sys)
grid
.

