How do I assign matrix of strings to matrix of numbers?

1 回表示 (過去 30 日間)
Surafel Taddesse
Surafel Taddesse 2019 年 7 月 11 日
コメント済み: Surafel Taddesse 2019 年 7 月 18 日
Lets sat I have:
a1 = [A,B,C,D,E,F]
a2 = [5,8,2,9,2,1]
lets assume this are large matricies.
Is there a way that I can get A = 5 , B = 8 , C = 2 ...... without having to do it individually. As long as their location is the same I want to set them their respective variable
Please help and Thank You in advance!
  2 件のコメント
Stephen23
Stephen23 2019 年 7 月 11 日
編集済み: Stephen23 2019 年 7 月 11 日
@Surafel Taddesse: dynamically accessing variable names is one way that beginners force themselves into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this:
In contrast indexing is neat, simple, easy to debug, and very efficient. You should use indexing.
Surafel Taddesse
Surafel Taddesse 2019 年 7 月 18 日
@Stephen Cobeldick
Thank you for the comment, I think you might have saved me many future Headaches.

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

採用された回答

David Goodmanson
David Goodmanson 2019 年 7 月 11 日
編集済み: David Goodmanson 2019 年 7 月 11 日
Hi [A,B,C,D,E,F] = deal(5,8,2,9,2,1)
although for a large number of variables, giving each its own name is not a winning strategy. In that case it is better to leave the numerical values in an array of some kind and access each value with an index, e.g. Z(ind) for a vector Z or Z(ind1,ind2) for a matrix Z, etc.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by