Converting Variable Name to String but Keeping Data!
이전 댓글 표시
Hi Folks! I would like to print a variable, and obviously its data, to the command window after my script finishes running. My variable is a not at all descriptive because it is nice and short so it makes my code look cleaner. However, when I print to the command window, I would like to print this variable as a better name, but having it consist of the same data to show... Any ideas on how to do this?
Thanks, Sean
댓글 수: 5
Guillaume
2016년 11월 5일
" My variable is a not at all descriptive because it is nice and short so it makes my code look cleaner."
That does not make your code cleaner, that makes your code unreadable. Self-documenting variable names is an important part of good code.
John D'Errico
2016년 11월 5일
Sadly, I cannot upvote a comment. Could I do so, I would do that for the comment by Guillaume though.
Star Strider
2016년 11월 6일
My sentiments exactly!
Sean Farrell
2016년 11월 6일
Guillaume
2016년 11월 7일
Oh, I understood the question perfectly well and had nothing to add to Star's and Walter's answer which showed exactly how to do what you want.
I wanted to comment solely on the portion I quoted, not the the general question. Having had to track down an obscure race condition in some colleague's code, my work was greatly hindered by having to remember what these "nice and short variable names" were meant to represent. If I don't have to engage my brain to try remember what's in each variable, I can focus it more on what the code is actually doing. (That particular case was not helped by the fact that these variables were also global. Arghhh!)
Think of us old people going senile ;)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!