Loren on the Art of MATLAB

Turn ideas into MATLAB

Age is No Barrier to Exploring Ideas and Concepts in MATLAB and Simulink 5

Posted by Loren Shure,

Age is No Barrier to Exploring Ideas and Concepts in MATLAB and Simulink

I’d like to introduce you to this week’s guest blogger, Graham Dudgeon. Graham is with our Industry Marketing Team at MathWorks, and focuses on the Utilities & Energy Industry. In this blog, Graham shares a story about age being no barrier to exploring ideas and concepts in MATLAB and Simulink.

Hi Everyone, and thank you Loren for inviting me to be a guest blogger. This story begins with my dog, waiting patiently at the patio door expecting either of my two sons to let her in. She was out of luck. I am no dog psychologist, but I figure that because she could see the boys very clearly, that they in turn could see her. In her mind, she didn’t need to bark to raise their attention…. and so on she waited while my sons continued watching Phineas and Ferb. Once I was alerted to her predicament a mere fraction of a second after entering the family room (by seeing her hopeful eyes and her tail wagging with a vigor in direct proportion to how long she had been waiting), I let her in and then reinforced to my sons that they need to be more aware of their surroundings. This is where MATLAB and Simulink come into the story… To help pooch out, I made a slight modification to demoimaqsl_rgbhistogram_win.slx , aimed the web cam at the patio door and when pooch came to the door, we were alerted to here presence by a ‘gong’ that I took from ‘gong.mat’, and had a MATLAB callback to execute the sound when a color threshold was reached – it turns out red works best for a fox hound. Was pooch consequently let into the house by my boys? Unfortunately not. The boys decided that a much better use of my endeavor was to see if they could creep past the field of view without the gong going off. This kept them entertained for longer than I expected.

My eldest son, who is 9 years old, started asking questions about how the model worked, how the camera worked, what was doing what, how do you detect pooch, etc. etc. I must have answered with sufficient clarity and enthusiasm as he decided to take what I had done and modify it for his Science Expo.

My son watched the RGB plot as we passed different colors in front, and gained a feel for how to develop a detection algorithm. Our process was to let my son watch only the RGB plot, not the object in front of the camera, and tell me what color he thought was there. ‘Red!’, ’Blue!’, ’Kinda red and blue, and a bit of green!’. We would then confirm his observations by looking at the actual object and moving it again across the field of view to see the RGB response change with the movement. My son associated y-axis magnitude with detection and figured out that to detect, he need simply tell the computer to ‘gong’ when a color got to a certain magnitude. My son also figured that you could remain ‘invisible’ if the detector was tuned only for red and you wore another color, and that a black background would cause less noise on the color signals, as black caused only a small RGB signal. My youngest son also helped out, by wearing different colored shirts and walking (sometimes running) past the web cam. The list of insights my son gained go on and on. He presented his work at the Science Expo, and was met with great enthusiasm and interest by the High School Scientists who assessed his work.

So how does this story end? A few days ago my eldest son told me that when he grows up he wants to be an engineer… and that he wants to work for MathWorks. On hearing this, my 5 year old son said he wanted to be a scientist (as he ‘wants to see into stuff’)… and that he too wants to work for MathWorks. So the story continues, and our future is in good hands

And what of pooch? She’s standing outside the patio door (with hopeful eyes and tail wagging vigorously) waiting for me to finish this post.

Before I sign off, let me give you my main takeaway from this story… You can use MathWorks tools to help kids of any age explore and evolve their curiosity, by connecting them directly to the world of Science and Engineering. Give it a try!

Get the MATLAB code

Published with MATLAB® R2014a

5 CommentsOldest to Newest

Doug replied on : 4 of 5

I decided to try this experiment with my 8 year old…but I can’t figure out how you triggered a sound. The “From Multimedia File” block doesn’t contain a trigger input. The article mentions using a Matlab callback…but which callback on which block? I am strong in Matlab, but not Simulink, so I’m struggling with something that’s probably simple.

Graham replied on : 5 of 5

Hi Doug,

We used a MATLAB function block that was driven by a ‘compare to constant’ block. When a threshold was reached, a logical 1 is sent to the MATLAB function which then generates the sound. The code for MATLAB function is,

function fcn(u1)



y = load(‘gong.mat’);

if u1 > 0.5



Hope this works. Let me know how it goes!