How to view parameter values while debugging in App Designer?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
採用された回答
Here are several methods of seeing the values of variables in AppDesigner code.
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. Learn more: setting break points.

See values by hovering the mouse over the variable or exploring the workspace.
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 will then have access to all variable values prior to the break point by hovering your mouse over the variable or exploring the workspace browser. Press F10 to step through the rest of the code line by line or F5 to coninue execution of 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 windowUse the ~fprintf(__) trick with conditional breakpoints
This is my favorite way to see what's going on inside the code without making any changes to the file. Set Conditional breakpoints in the file using a ~fprintf(__) statement. See my article on this topic in the Discussions area: Debugging Using Conditional Breakpoints & fprintf.
Add fprintf() commands in the code
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)
5 件のコメント
Thanks for the reply Adam.
I created a basic function that uses a parameter MyData (see second image).


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?
You can see the values in app.MyData by following the "See values by printing them in the command window." section of my answer.
For example, the MyData property was added to the app and then in the callback function, I put a break line at app.MyData, I highlighted app.MyData and then pressed F9.

Then, in the command window,

Keep in mind that on the first run, MyData is not yet defined and will be empty as you can see.
Another option is to save it to your workspace directly.
assignin('base','MyData',app.MyData)
Using this, you'll be able to type MyData in the command line and it will show your results. This is how I troubleshoot everything because printing every small variable to the command window can be tedious for app designer.
I would recommend avoiding the use of assigning() in this case, for the following reasons.
- 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.
- 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.
- You risk overwriting variables in the designated workspace that you may want to keep.
- As alluded to above, you must remember to comment-out or remove those lines of code which is additional work.
- 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.
@Adam Danz another way is that if you've set a breakpoint then the variables should be in the workspace panel in MATLAB. So you can just thrash your window from AppDesigner over to MATLAB and look in the workspace panel (type worspace in the command window if the workspace panel is not visible). For small variables you can see the variables right away in the workspace panel. For larger variables, like structure arrays and cell arrays, you can double click on the variable name in the workspace panel to open it up in the Variable Editor window.
But all 3 of these workarounds are not ideal. We don't want to have to switch over to another window (MATLAB). We want to have the workspace panel and the command window all available right in app designer. Or somehow create a unified, consolidated UI that combines MATLAB and AppDesigner into a single window with all the panels that we need.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Develop Apps Using App Designer についてさらに検索
製品
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
