Perform an action with multiple variables

조회 수: 2 (최근 30일)
Kylie Hansen
Kylie Hansen 2017년 7월 10일
편집: Kylie Hansen 2017년 7월 10일
Hi, all! I have a lot of variables (over 2000 and counting), and I need to perform the same action on all of them. As of now, each variable is a Cx5 matrix where C is a very large number. I simply want the second column in each matrix. I realize that you can access the second column through
A(:,2)
but I am not sure how to do this for multiple variables. Each variable is similarly named; in my specific scenario, I have named each blg_x where x is the identifying number for the variable and the only aspect that will change (e.g. blg_0001, blg_1970). I have played around with loops that try to change variable names in them, but nothing seems to work. I was thinking that perhaps MATLAB has some way to perform an action on variables starting with certain letters (in my case 'blg') that I am not aware of, or some way to step through variable names like in a for or while loop. Some help would be appreciated!
  댓글 수: 1
John D'Errico
John D'Errico 2017년 7월 10일
The short answer is: don't do it.
Longer: D o n ' t d o i t.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 10일
  댓글 수: 1
Kylie Hansen
Kylie Hansen 2017년 7월 10일
편집: Kylie Hansen 2017년 7월 10일
Even if it is frustrating, forced learning is the ultimately best route. Thank you for sharing. You now have one less beginner using cell() instead of eval(). EDIT: After spending a bit more time with this, I've learned a lot more than I expected. Just thought I'd come back to this post to say thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by