Monitoring Variables Defined Within Functions to Debug

12 ビュー (過去 30 日間)
LW
LW 2025 年 11 月 7 日
編集済み: Torsten 2025 年 11 月 7 日
I have a program I'm running that uses a function I've written. In some cases where the function is called, it throws an error, and in other cases, it does not. Matlab tells me that there's an issue with one of the variables defined inside the function, however I do not see the variable in the workspace. How do I look at the values held in variables local to my functions?

採用された回答

Torsten
Torsten 2025 年 11 月 7 日
編集済み: Torsten 2025 年 11 月 7 日
After the variable is computed, you can list the variable's name by itself on it's own line in your function code, with no semicolon after it. When execution hits that line of code, it will spew the value of the variable out to the command window.
Example: The following code displays the values of b taken in function "test".
test(4)
b = 5
b = 7
b = 9
b = 11
function [] = test(jmax)
for j = 1:jmax
a = 2*j;
b = 3 + a;
b
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by