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

6 visualizzazioni (ultimi 30 giorni)
bkshn
bkshn il 19 Feb 2015
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 Commenti
bkshn
bkshn il 19 Feb 2015
Thanks Akshata M it's work!
Michael Haderlein
Michael Haderlein il 19 Feb 2015
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.

Accedi per commentare.

Risposte (2)

Stephen23
Stephen23 il 19 Feb 2015
Modificato: Stephen23 il 19 Feb 2015
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.

Michael scheinfeild
Michael scheinfeild il 19 Feb 2015
use strcmp

Community Treasure Hunt

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

Start Hunting!

Translated by