필터 지우기
필터 지우기

Help with rowfun?

조회 수: 8 (최근 30일)
amen45
amen45 2017년 2월 21일
댓글: Rik 2017년 2월 24일
I've created a table with columns Go,Export, and Directory and row names from a list of strings (ex {'First Row','Second Row'})
I have a helper function, generic_helper that takes each of a Go, Export, and Directory values from a table, along with the string corresponding to the row (ex 'First Row') and a binary flag that does not change across rows.
How can I apply rowfun to call generic_helper(Go,Export,Directory,rowName,ex_bin_flag) for the values of Go,Export,Directory, and rowName in each row of my table?
Thanks in advance!
  댓글 수: 2
Rik
Rik 2017년 2월 21일
Have you considered a for-loop? If so, why doesn't that do what you need?
amen45
amen45 2017년 2월 21일
I have one now, but as I understand with tables in matlab vectorizing is particularly advantageous in terms of speed (unlike say cellfun for cell arrays). if I'm mistaken, I'd love an explanation!

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

답변 (1개)

Rik
Rik 2017년 2월 22일
You should have the helper function with some output (one or multiple scalars (single values)). Then, in your code you can use
newtable=rowfun(@generic_helper,table);
Note from rowfunc doc: "To return more than one output from func, use the 'NumOutputs' or 'OutputVariableNames' name-value pair arguments."
PS you were correct in looking for a vectorized solution, they are indeed generally faster. For smaller problems the effect is often negligible, but it always affects readability.
  댓글 수: 10
amen45
amen45 2017년 2월 24일
sorry, should have been more specific. they are globals that are passed to the generic helper function, as shown in my example code above. This is all happening in a larger module.
Rik
Rik 2017년 2월 24일
Well, then you can either declare bin_flag and rowName as global variables, or create two new global variables in which you paste the content of bin_flag and rowName.

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by