Sprintf warning message on a function file
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello, i created a function file where need to use sprintf, but theres a warning message that say to use fprintf instead, in this case i really need to use sprintf, because i´m exctracting specific values from a vector, and fprintf wil print a number before the text that i printed... do you know any alternative that works like sprintf, to make the warning message go away? Thanks a lot!
%On a function file...
%rest of my code...
equacao_1=sprintf('The equation of the fitted function is: y= %f*x + (%f).',p1(1),p1(2));
disp(equation_1),disp(' ')
This is the message that appears...the program run, but i don´t want to see this message.
댓글 수: 0
채택된 답변
Voss
2023년 1월 22일
The warning is saying that, if all you do with the result from sprintf is to display it with disp, then you can display it with fprintf instead.
p1 = [5 6];
equacao_1=sprintf('The equation of the fitted function is: y= %f*x + (%f).',p1(1),p1(2));
disp(equacao_1)
fprintf('The equation of the fitted function is: y= %f*x + (%f).\n',p1(1),p1(2));
If you use equacao_1, the result from sprintf, somewhere else in your code to do something besides display it with disp, for example to set it to the title of a plot, then the warning will go away. Alternatively, you can right-click and disable the warning (on that line, in that file, or in all files), or set the warning to be disabled by editing your preferences (Preferences>Code Analyzer).
댓글 수: 5
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!