How define a variable like pi in matlab?
조회 수: 4 (최근 30일)
이전 댓글 표시
I want to define several variables like pi,maybe we can call them the constant value, and call them in the functions without defining the twice time. I can not use the global variable because there are almost 100 function files in our project and I do not want to declare them in every function files, it's too troublesome.
I've tried to write the variable in the matlabrc.m, but I can only call the variable in the command window and when I call it in the function file, the matlab told me that it's an undefined variable.
So please tell me how to solve this problem, it's really appreciated of you.
I'm looking forward to your answer.
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2013년 12월 24일
create a function
function out=cst1
out=0.12453648
then call the function cst1
a=cst1
댓글 수: 0
추가 답변 (1개)
per isakson
2013년 12월 24일
편집: per isakson
2013년 12월 24일
Another way:
>> my_constants.pi
ans =
3.1416
where
classdef my_constants
properties ( Constant = true )
pi = 355/113;
etc = 17;
end
end
Pro: all constants in one file
Con: an extra string in the call
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!