Can't find where the warning msg is from
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone,
I have been receiving a warning message saying 'no regexp for "double"'. According to the warning message showed, it occurred at the line coded like this: notify(obj,event,myinput);
I can't figure out what triggered the warning since it's only the notify function. and myinput is a structure. I also have checked the code that calls notify(obj,event,myinput).
Appreciated if anyone can help!
0 commentaires
Réponses (4)
per isakson
le 24 Avr 2013
Modifié(e) : per isakson
le 29 Sep 2017
Matlab fails to provide a meaningsful error message in this situation. It's left to the user to provide a work-around.
Here is a small example of my work-around. It is code from the on-line help with a bit of error handling added together with code that causes an error: buf = 1; disp( buf(2) ). The trick is: try, overflowHandler_(eventSrc,eventData), catch me, disp(getReport(me)), end
Run
sec = setupSEC;
sec.prop1 = 5;
sec.prop1 = 15;
returns to the command window
The value of Prop1 is overflowing!
It's value was: 5
It's current value is: 15
Attempted to access buf(2); index out of bounds because numel(buf)=1.
Error in overflowHandler>overflowHandler_ (line 13)
disp( buf(2) )
Error in overflowHandler (line 3)
overflowHandler_( eventSrc, eventData )
Error in SimpleEventClass/set.prop1 (line 14)
notify( this,'Overflow',SpecialEventDataClass( org_value ) );
where
function sec = setupSEC
% Create an object and attach the listener
sec = SimpleEventClass;
addlistener( sec, 'Overflow', @overflowHandler )
end
and
classdef SimpleEventClass < handle
properties
prop1 = 0;
end
events
Overflow
end
methods
function set.prop1( this, value )
org_value = this.prop1;
this.prop1 = value;
if ( this.prop1 > 10)
% Trigger the event using custom event data
notify( this, 'Overflow', SpecialEventDataClass( org_value ) );
end
end
end
end
and
classdef SpecialEventDataClass < event.EventData
properties
OrgValue = 0;
end
methods
function eventData = SpecialEventDataClass( value )
eventData.OrgValue = value;
end
end
end
and
function overflowHandler( eventSrc, eventData )
try
overflowHandler_( eventSrc, eventData )
catch me
disp( getReport( me ) )
end
end
function overflowHandler_( eventSrc, eventData )
disp('The value of Prop1 is overflowing!')
disp(['It''s value was: ' num2str( eventData.OrgValue )])
disp(['It''s current value is: ' num2str( eventSrc.prop1 )])
buf = 1;
disp( buf(2) )
end
I use the same approach with code invoked by a timer. I've found it really helpful. See Debug code invoked by timer
0 commentaires
Image Analyst
le 24 Avr 2013
First, review this link: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/. Then step through your code with F10 (step over) and F11 (step into) until you see red text barfed up into the command window. Then you'll know what line it happened on. You can speed past sections of code by setting breakpoints. By the way, did you search your code for regexp?
1 commentaire
Daniel Shub
le 25 Avr 2013
I am not sure that debugging callbacks in this way is really viable. I am not even sure how the event queue is handled when you are in debug mode. I am pretty sure if timers are involved that you would have a disaster on your hands.
Walter Roberson
le 24 Avr 2013
What is class(event) ? It needs to be a string and you might get that warning if it was not.
0 commentaires
Daniel Shub
le 25 Avr 2013
The idea of notify(obj,event,myinput) is that MATLAB sends a signal to all objects that are listening for the event event. You will not find this object/callback by looking at your code in a linear manner. You want to look for where the listener was created. This is usually done with addlistener
0 commentaires
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!