Taking individual values from an array

P=[1 3 6 7 8] P1=P(1) P2=P(2) P3=P(3) P4=P(4) P5=P(5)
instead of using the above commands for taking individual values of P1-P5 from the array,need a simple command that can load data

3 件のコメント

KSSV
KSSV 2016 年 10 月 13 日
Where you want to use the data, you can call it by using P(1) or P(2), etc using indices. What else you are expecting ?
Bilal Khurshid
Bilal Khurshid 2016 年 10 月 13 日
P=input(' Enter Processing times of 5 jobs ')
P1=P(1) P2=P(2) P3=P(3) P4=P(4) P5=P(5)
If i have to enter data for 30 machines it becomes difficult and also looks ugly, need a simple command for that ,so that it takes values
e.g Pi=P(i) where i=1:no of jobs
Stephen23
Stephen23 2016 年 10 月 13 日
@Bilal Khurshid: your choice is between indexing and dynamic string evaluation:
Indexing:
  • simple
  • fast
  • easy to read
  • best practice
  • used by experts
Dynamic variable names:
  • slow
  • buggy
  • difficult to debug
  • used by beginners
Which one are you going to choose?

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

回答 (1 件)

KSSV
KSSV 2016 年 10 月 13 日

2 投票

What you want to do is not suggested. Better you proceed with the matrix/ array itself.
check the link:

1 件のコメント

Guillaume
Guillaume 2016 年 10 月 13 日
Yes! Do not use numbered variables.
You have a very convenient way to access the Ps you want, it's called indexing. Any workaround that you may find will be slower, buggier, harder to read and certainly a lot uglier than a pair of parentheses.

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

カテゴリ

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

タグ

質問済み:

2016 年 10 月 13 日

コメント済み:

2016 年 10 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by