How do i make print the variable name for a certain variable
조회 수: 3 (최근 30일)
이전 댓글 표시
Suppose there's this array [a,b,c,d . . . ].I'm trying to write a program that takes the product of two variables a and b and if a*b is in the array then it will print the variable name. For example if a=3 b=2 and c=6 then myfunction(a,b) will return the string'c'
댓글 수: 4
Guillaume
2016년 10월 3일
"Suppose there's this array [a,b,c,d . . . ]"
There is no array [a,b,c,d...]. There may be an array that is the result of concatenating [a,b,c,d...] but at this point matlab does not know anymore that the array values came from a,b,c and d.
Your whole setup sounds like a bad idea. There is never a good reason for a function to return the name of a variable.
답변 (2개)
Gareth Thomas
2016년 10월 3일
myw=who;
now all you need to do is cycle through the values of the variables and return the myw.name(ind)
댓글 수: 0
Gareth Thomas
2016년 10월 3일
If I understand you correctly you would like to print a the content of a variable.
a = 2;b = 3;c = a*b;disp(c)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!