Help with rowfun?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!