How to get data from variables that change the name?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have the variables day1,day2,day3....day15. I want to get the data of each variable within a loop. How I can do it?
Thank you in advance
댓글 수: 2
답변 (2개)
John Chilleri
2017년 1월 13일
Hello,
A simple solution would be:
Days = [day1 day2 day3 ... day15];
Then call Days(:,i) for the ith days data if it's a vector (assuming column vectors), or just Days(i) if it's a scalar.
Hope this helps!
댓글 수: 0
Image Analyst
2017년 1월 13일
The "data of each variable" and the variable itself are one and the same thing. Just assign it to another variable if you want, or just start using it.
someOtherVariable = day1;
someOtherVariable2 = day2 * pi * log(42);
someOtherVariable3 = day5 * cos(day12) + day9;
result = SomeFunction(day7);
and so on. You don't need to do anything special to the variable to access it's "data". The variable and its data are the very same thing.
댓글 수: 2
Image Analyst
2017년 1월 14일
See the FAQ for why this is a horrible idea: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!