Clear Filters
Clear Filters

Ode45, Events error: SWITCH expression must be a scalar or a character vector

7 views (last 30 days)
Hi, I have this problem using "Events" option for ode45.
In the main I have:
Tol0 = 1e-13;
Tol1 = 1e-13;
options = odeset('Events', @myEvent, 'RelTol', Tol0, 'AbsTol', Tol1);
s0 = [1, 2, 3, 4, 5, 6];
tspan = [0 100];
[time,S] = ode45('Dyn', tspan, s0, options);
My event function is:
function [value, isterminal, direction] = myEvent(t,S)
value = S(2);
isterminal = 1;
direction = 0;
end
The error appearing in the command window is:
SWITCH expression must be a scalar or a character vector.
Error in odeevents (line 34)
switch lower(eventFcn)
Error in ode45 (line 137)
odeevents(odeIsFuncHandle,ode,t0,y0,options,varargin);
Error in Main (line 31)
[time,S] = ode45('Dyn', tspan, s0, options);
Could you help me?
Thank you.
  3 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 30 Nov 2023
I have seen this before when the person had a third-party version of lower in their MATLAB path. Please show
which -all lower
built-in (/MATLAB/toolbox/matlab/strfun/lower) lower is a built-in method % string method /MATLAB/toolbox/parallel/parallel/@codistributed/lower.m % codistributed method
The interfering toolbox was something like EEGLab or SPM12 or something-or-other-8 (I forget the name)
  2 Comments
Alice Bobbi
Alice Bobbi on 30 Nov 2023
Thank you but the error was another one. If the option Events is used, I have to recall the integrated function as @Dyn, not 'Dyn'.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!