How to view parameter values while debugging in App Designer?

235 views (last 30 days)
AS
AS on 9 Jan 2020
Commented: Adam Danz on 13 Jan 2020
Hi,
I am new to App Designer and have a quick question. I am trying to convert a few scripts over to App Designer so there is a user interface. I am unable to view the parameter values while trying to debug the app. Is there a way to view the parameter values similarly as you would when debugging a script (view in workspace)? There are parameters showing in the workspace but I can't view the values in the parameters.
Thanks,
Art

Accepted Answer

Adam Danz
Adam Danz on 9 Jan 2020
Edited: Adam Danz on 9 Jan 2020
Here are 3 methods of seeing the values of variables in AppDesigner code.
The first two require using debug mode.
Set up debug mode
Place a break point anywhere within the function that stores the variables you'd like to explore. You can place a break point by clicking on the gray horizontal line along the left edge next to the line numbers.
See values by hovering the mouse over the variable.
After setting the break point, run the app and execute the callback function that contains the line break (example: press the button that calls the callback function). If the line break is in the startup function, just run the app. When execution gets to the break line, execution will pause and you then will have access to all variable values prior to the break point by hovering your mouse over the variable. Press F10 to step through the rest of the code line by line or F5 to finish running the code.
See values by printing them in the command window.
Instead of hovering the mouse over the variable as explained above, you could highlight the variable and press F9 which will print its value to the command window.
+ F9
<--- command window
Print the value of variables by using fprintf() commands
Use an fprintf() command as shown below to see the value of variable 'x' in the command window every time this line is executed.
fprintf('x = %.5f \n', x)
% [1] [2]
% [1] this will show 5 decimal places
% [2] this will add a new line after showing the variable value
For more complex variables such as the content of structure 's'
fprintf('s = \n')
disp(s)

More Answers (1)

AS
AS on 9 Jan 2020
Thanks for the reply Adam.
I created a basic function that uses a parameter MyData (see second image).
1-9-2020 1-23-33 PM.jpg
1-9-2020 1-27-29 PM.jpg
I want to be able to see what values are in MyData for debug but can't. If MyData is not a parameter and just a variable in the function then I can see that in the Workspace. I need to be able to store MyData for other functions to use. What am I missing?
  3 Comments
Adam Danz
Adam Danz on 13 Jan 2020
I would recommend avoiding the use of assigning() in this case, for the following reasons.
  1. Debug mode is designed exactly for this reason: to explore variable values within function workspaces; and it avoids the rest of the problems liste below.
  2. assigning() results in variables 'magically' appearing in the designated workspace whose origins are very difficult to trace. It's easy to forget to comment-out these lines of code which could result in a nightmare of variables appearing without trace.
  3. You risk overwriting variables in the designated workspace that you may want to keep.
  4. As alluded to above, you must remember to comment-out or remove those lines of code which is additional work.
  5. Sharing the content of a variable may not be that informative without knowing the content of other variables. This is not a problem when using debug mode.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!