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)?
Konstantinos Kotsis
2021년 5월 23일
"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.
답변 (1개)
Steven Lord
2021년 5월 20일
0 개 추천
Can you do this? Yes.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!