I like to create multiple variables with different values. like A1= 5, A2 = 3, A4 = 2,....,A100 = 30.
I want all these variables separate because I have to insert these variables names in a cell array. Also, How to create separate variables with Zero values?

1 件のコメント

Stephen23
Stephen23 2016 年 6 月 1 日
@Heet: don't create variables like that, it is a slow and buggy way tow rite code. Just use indexing: this is a fast and reliable way to write code.
Beginners often think that creating variable names would be a great idea. It isn't.

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2016 年 6 月 1 日
編集済み: Stephen23 2019 年 6 月 19 日

0 投票

2 件のコメント

TEEH
TEEH 2016 年 6 月 1 日
@stephen thanks for your answer. Being a beginner in MATLAB, I do not have knowledge of all its tools and features. So here I am explaining you my problem so that you could direct me towards the right direction.
I would like to SET UP A LINEAR Program whose constraints will be defined by me, but the number of variables is supplied by the user. So there to form matrix A and b. I need to supply different variables in the cell array as shown in the example. As per my knowledge, there is no alternative to it.
I hope you could help me in this problem.
Stephen23
Stephen23 2016 年 6 月 1 日
編集済み: Stephen23 2016 年 6 月 1 日
@Heet: Well, you say that you need the variables in a cell array... then use a cell array. Another simple choice would be to use a structure.
Or you could actually read the page that you linked to, and you will find this sentence: "The video Optimization Modeling 2 shows how to solve the problem simply using the index numbers of the components of x."
Did you look at the video ?
Note how it uses indexing... which is much more reliable than generating variables using eval.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

質問済み:

2016 年 6 月 1 日

編集済み:

2019 年 6 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by