How to include the value of a function into a variable?
Ältere Kommentare anzeigen
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 Kommentare
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
am 23 Mai 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.
Antworten (1)
Steven Lord
am 20 Mai 2021
0 Stimmen
Can you do this? Yes.
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!