Clear Filters
Clear Filters

Why can't I see instantiated objects with the Simulink debugger?

2 views (last 30 days)
I have some embedded matlab code inside a Simulink simulation and I'm instantiating some objects. When I step through with the debugger and set a breakpoint in the embedded matlab, I can see all the other local variables (as expected) but I cannot see the object or do anything with it that I normally could when stepping through with the Matlab debugger (outside of Simulink). The code does still run, I just can't see it in the debugger.
Any idea why? Is there a way around this?
dvd7e on 25 May 2018
Sure. As a simplified/dummy model, my Simulink is just a Matlab function, with the following code:
function y = fcn()
% Create the car object at simulation startup
persistent bmw
if isempty(bmw)
bmw = car('bmw'); % Instantiate the car object
% Every time step move the car's position
% Output the current car position
y = bmw.pos;
and this is the class definition for a "car":
classdef car < handle
name = '';
m = 1000;
pos = 0;
function obj = car(nameIn) = nameIn;
function obj = move(obj,stepVal)
obj.pos = obj.pos + stepVal;
function obj = resetPos(obj)
obj.pos = 0;
When I run this in Simulink it behaves as expected. Every iteration it moves the car position by 1 and outputs that position. The issue I'm seeing is that when I use the debugger to step through and put a breakpoint in the embedded matlab, I can't see the car object or any of its methods or properties. I usually can do this with the Matlab debugger, but apparently not in Simulink. On the other hand, I can see "normal" variables in the debugger, like the output "y".
Without being able to interact with the objects from the debugger/command line, it makes it much harder to debug or investigate what's going on.

Sign in to comment.

Answers (0)


Find more on Simulink Functions in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!