How do I display the code line number?

조회 수: 16 (최근 30일)
Sebastian
Sebastian 2016년 5월 9일
댓글: Sebastian 2016년 5월 13일
Hello! Of all the questions people have asked, noone seem to have been wondering about this. Please correct/redirect me if I'm wrong!
Let's say I have a large amount of unique if-loops that are pretty much similar. Every if-loop has two options where the first is the actual script, and the other one is just a sort of else-prompt that only shows very rarely, or even never.
If I in the else-option want to use disp('This was not what you wanted') and after that tell me where in my code I actually am, like what code-line am I at, how could I do that?
If I get an error from, really whatever, it tells me what function file and what line number I'm at. This I want to be able to call myself. I know I can do it manually easily with something like disp('This was if-loop "Adam", and it wasn't right').
Thanks!

채택된 답변

Fangjun Jiang
Fangjun Jiang 2016년 5월 9일
I suggest using the warning('msg'). It will tell you the code line number in the Command Window when it happens.
  댓글 수: 1
Sebastian
Sebastian 2016년 5월 13일
Cool!
Even though it might feel a little bit aggressive to send out a warning in this case just because the numbers actually were too good to begin with, so an extra interpolation on my results would be redundant, it still does the job just perfectly for this program! And since my function never really does get the numbers that good, I will never get to see the warning anyway.
Many thanks Fangjun for your quick help to my not-even-really-a-problem! I appreciate it!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by