How to include the value of a function into a variable?
Mostrar comentarios más antiguos
Hello all,
I have a function with a certail value. Let consider an example :
fix(u/l_segment) = 10
And what I want to do is to include the value of this function into the variables that I am going to declare. Something like this :
Coefficient_[fix(u/l_segment)] = 1 ; (so in this case my variable would become Coefficient_10)
Coefficient_[fix(u/l_segment) - 1] = 1 ; (so in this case my variable would become Coefficient_9)
And so on...
Any idea how can I do this?
Thank you in advance!
3 comentarios
Forcing meta-data into variable names is one way that beginners force themselves into writing slow, inefficient, complex code.
Is there any particular reason why you cannot use indexing and/or simply store the meta-data in its own array?
Is there any reason why you cannot use arrays/matrices/vectors (which is exactly how MATLAB is designed to be used)?
Konstantinos Kotsis
el 23 de Mayo de 2021
"I hope this clears out things a little bit."
Yes, it makes it quite clear that dynamically naming variables would be a pointlessly complex and inefficient approach.
"If you have any suggestions or recommendations"
Exactly as I wrote in my previous comment you should use indexing, possibly storing that meta-data in its own array.
Respuestas (1)
Steven Lord
el 20 de Mayo de 2021
0 votos
Can you do this? Yes.
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!