How to have presistent physical constants?
이전 댓글 표시
Hello,
I know Matlab can do pi. I would also like to add values for other constants such as electron charge, Boltzman constant, etc. and simply have them accessible as ec and kb. However, I don't want them to get wiped out when I do a "clear all" command, so simply defining them in startup.m isn't what I want. Basically, I want them to be treated just like how Matlab treats pi (i.e. they still exist even after I clear all variables). Is there a simple way to do this?
Thanks
댓글 수: 1
per isakson
2017년 1월 26일
편집: per isakson
2017년 1월 26일
채택된 답변
추가 답변 (1개)
Walter Roberson
2017년 1월 26일
0 개 추천
pi is a function. It even takes arguments.
Some people prefer to use a Package to store constants and import from the package
댓글 수: 3
per isakson
2017년 1월 26일
편집: per isakson
2017년 1월 26일
"It even takes arguments."   Not R2016a - afaik
>> pi(3)
Error using pi
Too many input arguments.
Walter Roberson
2017년 1월 26일
I thought I had once used pi('single') . Perhaps I misremembered.
Steven Lord
2017년 1월 31일
I don't think pi has ever accepted an input argument. You may be thinking of Inf, NaN, ones, zeros, etc. which do allow you to specify just a class name to obtain an appropriate scalar. Different functions accept different class names. For example if you try to call NaN('int32') it will error but ones('int32') will work fine.
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!