How to name Array with each of my Arrays in a bulk folder?

1 回表示 (過去 30 日間)
Jeremy Choo
Jeremy Choo 2021 年 9 月 28 日
回答済み: Ravi Narasimhan 2021 年 9 月 28 日
This is a simple problem yet I can't seem to solve it. I have a set of arrays in a file called 'results'. There are 8 in total, so far I want to separate all of them, to get Array1 = results{1,1}, Array2 = results{2,1}, etc. However, i can't seem to create a for loop that does this. I've tried i=1:length(results), which should give me i=1:8, but hw do i incorporate that into my Array name? Array(i) gives me the porperties of the array instead, which I do not want. Is there a simple way to get Arrayn = results{n,1}?

回答 (2 件)

Jan
Jan 2021 年 9 月 28 日
編集済み: Jan 2021 年 9 月 28 日
Do not hide an index in the name of variables. Although it is piossible to do this using the eval command, it increases the complexity of the code without any benefit, and impedes the processing such that the code can need up to 100 times more tome to be executed.
result{n} is ways better than Array1, Array2, ...

Ravi Narasimhan
Ravi Narasimhan 2021 年 9 月 28 日
I believe what you are requesting (dynamically naming variables) can be done but is strongly discouraged. Here is a reference for why and how to achieve equivalent results in different ways. There are multiple links within that main one that are worth the time.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by