Your code is completely inappropriate for what you are trying to achieve. You should read How Simulink Works (and the pages linked off that page) to get a better understanding of what it is and how to use it.
The sim
function will simulate your model from the start time to end time (that you have specified in your model, not your variable t
) You should not be using it in a loop where you (think you) are incrementing time yourself - the Simulink solver
does that for you.
The way you have set up the From Workspace
block requires you to define, in MATLAB, a variable called t
and another called v1
, both of which must be column vectors. (It looks like you also need to define a variable called tauf
, although it's not clear what that block is so I can't be sure.)
t=0:0.001:5
v1=...
Specifically note that t
is used to define the time points at which v1
changes, it has nothing to do with the time steps taken by the Simulink solver stepping the model through time.
Then you want to run the simulation,
sim('v1delay');
This will generate a variable called v1_delay
in the MATLAB Workspace. The To Workspace
block allows this to be one of several different data-types. Depending on which one you have selected, you will use slightly different functionality to access the actual numeric data to calculate your z
variable.
z=??? % syntax will depend on the data type of v1_delay