hi i am new on matlab, i want to know who i define Constants like gravitation. in c++ it was super easy (define g=9.8) but in matlab i don't understand it.

댓글 수: 1

James Tursa
James Tursa 2018년 8월 15일
편집: James Tursa 2018년 8월 15일
If you mean something equivalent to the "const" keyword attribute for a variable, then no MATLAB does not have this capability for basic numeric variables.

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2018년 8월 15일

0 개 추천

even easier
>> g=9.8
g =
9.8000

댓글 수: 5

nitzan netzer
nitzan netzer 2018년 8월 15일
the problem is that i use in alot of function and i need to define it all over again every time. (i dont want to use a global becuse bad programming and slow)
James Tursa
James Tursa 2018년 8월 15일
편집: James Tursa 2018년 8월 15일
@nitzan: This statement does not take much time in MATLAB and I wouldn't worry about it. In fact, later versions of MATLAB might even keep a reference copy of this in the background so that successive times you hit this line don't even allocate anything new ... you just get a reference to what was saved. Other parts of your code are very likely dominating your run time, so spend your effort improving that code instead of this line.
All true, @James Tursa!
If you insist, you can save the following two lines as G.m and include its folder location in your MATLAB path. Then you can use "G" whenever you want.
function out=G
out=9.8;
>> a=2*G
a =
19.6000
nitzan netzer
nitzan netzer 2018년 8월 15일
ok,thank you very much for solution and fast answer very much. it's help me
Walter Roberson
Walter Roberson 2018년 8월 15일
편집: Walter Roberson 2018년 8월 15일

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 8월 15일

편집:

2018년 8월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by