How to include the value of a function into a variable?

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 个评论

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)?
Hello Stephen,
Thank you for your comment.
Well, if I understand your question correctly: In my case and for my system, fix(u/l_segment) will take values from 1 to 1417. In every instant however, I will be only studying/referring to the components starting from [fix(u/l_segment)] till [fix(u/l_segment) - 9]. And these components can be anywhere between 1-1417, depending on the result I get from fix(u/l_segment) for that point in time.
So as you can understand, the variables that I'll be considering for my system, depend on the value of fix(u/l_segment) and that is why I need to consider the value of fix(u/l_segment) and use it as an indicator to understand what component number am I dealing with/working on.
I hope this clears out things a little bit.
If you have any suggestions or recommendations, I'd be happy to hear them.
"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.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by