variables in m files
이전 댓글 표시
Hi, I am new to MATLAB. This is the script i am working on:
FC = 360;
d = hex2dec ('*001C72*');
p = hex2dec ('*038E*');
t = hex2dec ('*0392*');
A = (d*0.5*FC/2^18);
B = (p*0.5*FC/2^15);
C = (t*0.5*FC/2^15);
Then writing 'A' in the command window i recieve an output in degrees depending on what the input 'd' is. My problem is that the hex values of d, p and t will change and not always equal the same. So is there any way that i can make the highlighted parts above a variable that i can somehow change without editing the m file everytime?
Many thanks
채택된 답변
추가 답변 (2개)
Define function
function A B C = myfunction(d, p, t)
FC = 360;
A = (hex2dec(d)*0.5*FC/2^18);
B = (hex2dec(p)*0.5*FC/2^15);
C = (hex2dec(t)*0.5*FC/2^15);
Call function with values for d, p and t, e.g.,
[ A B C ] = myfunction('*001C72*', '*038E*', '*0392*');
Jan
2013년 2월 11일
Str = '001C72';
d = hex2dec(Str);
Such basic methods are described in the Getting Started chapters of the documentation. To use a powerful tool like Matlab efficiently, it is strongly recommended to read the manual. The forum is not the right location to learn the basic, because the manual is written well and descriptive enough already.
카테고리
도움말 센터 및 File Exchange에서 Help and Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!