Unrecognized function or variable 'printstat'. Error in manet (line 162) if printstat == 1
4 次查看(过去 30 天)
显示 更早的评论
Getting Unrecognized function or variable 'printstat'. error. Please can anyone help? Thanks.
%% print statistics
if printstat == 1
simstat(ini.globals.SIMTIME,Nodes,ini.globals.SENDERS,ini.globals.RECEIVERS,Protocols,Apps);
end
0 个评论
采纳的回答
albara
2023-4-29
It looks like you're trying to use the variable printstat in your MATLAB script but it hasn't been defined yet. That's why you are getting the error "Unrecognized function or variable 'printstat'." To fix this error, you need to define the variable printstat before using it in the conditional statement.
For example, if you want to use the printstat variable as a flag to decide whether to print statistics or not, you can set it to 1 (true) or 0 (false). Add the following line before the conditional statement:
printstat = 1; % Set printstat to 1 (true) to print statistics, 0 (false) otherwise
Your updated code should look like this:
printstat = 1; % Set printstat to 1 (true) to print statistics, 0 (false) otherwise
%% print statistics
if printstat == 1
simstat(ini.globals.SIMTIME,Nodes,ini.globals.SENDERS,ini.globals.RECEIVERS,Protocols,Apps);
end
Now your script should run without encountering the "Unrecognized function or variable 'printstat'" error.
Waiting for your feedback
Important: There may be some mistakes in this answer Experts can tell if there are any mistakes
8 个评论
Walter Roberson
2023-4-30
ini is created by
ini = ini2struct('config.ini')
so the implication is that SENDERS should be part of config.ini
Walter Roberson
2023-4-30
The code expects to use ini.globals.SENDERS but the config.ini file defines SENDERS in the constants section, ini.constants.SENDERS
The config.ini file defines printstats in the visuals section, so the reference should be to ini.visuals.printstats
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!