How Can I use a string value as a parameter name?

Hello
How Can I use a string value as a parameter name?
I have a function that return a string value, I want to use this function in another function and use this string value as parameter name that is a Image.
Could You help me?
thanks

댓글 수: 4

have you tried using 'eval'
I don't quite get the question. When you do something like
[filename,pathname]=uigetfile;
img=imread(fullfile(pathname,filename));
then you already do exactly what you want. You have a function (uigetfile) which returns a string value (or, in this case, two values) and you use it as parameter.
bkshn
bkshn 2015년 2월 19일
Thanks Akshata M it's work!
I don't know your code and, as mentioned before, I didn't really understand the question. But in 99 % of the cases using eval is not the best idea. Besides issues such as slow execution, it makes debugging very difficult. There are cases when eval is the best (or the only) way, but that's limited to the 1 % remaining in my statistics. In all other cases, I'd not recommend it.

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

답변 (2개)

Stephen23
Stephen23 2015년 2월 19일
편집: Stephen23 2015년 2월 19일

1 개 추천

You can allocate that string to a variable, and use that variable in the next function:
str = firstFunction(...);
secondFunction(str)
This will call the second function with whatever string the first function returned.
If you are talking about using a string to dynamically name a variable, then don't do this and use a cell array or structure instead.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2015년 2월 19일

댓글:

2015년 2월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by