필터 지우기
필터 지우기

repeat the same function on multiple variables/handles

조회 수: 5 (최근 30일)
Victor
Victor 2014년 3월 12일
댓글: dpb 2014년 3월 13일
i have 20 handles that I set to enable on, i.e. set(handle,'enable','on') and the same thing with off.
Is there a more efficient way to do this than using the set function 20 times? For example, is there a way to pass a list of the handles to a function that will repeat a function over the entire list?

채택된 답변

dpb
dpb 2014년 3월 13일
set accepts a handle vector and operates on each. Just use the array form. Note the property name and value can be cell arrays as well. See
doc set % for details
  댓글 수: 2
Victor
Victor 2014년 3월 13일
Thanks. Is there a way to do something similar with a more generic function than set? for example if I have 20 string variables and I want to add an 's' to the end of every string.
dpb
dpb 2014년 3월 13일
Sure...almost every Matlab builtin is vectorized. And, you can write your own functions in almost every case to also use vectors/arrays as inputs and generate same.
Looks like you need to go to the documentation and start at the "Getting Started" section and work through the examples of how Matlab works to get a feel for using it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by