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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by