Comments for Loren on the Art of MATLAB https://blogs.mathworks.com/loren Loren Shure is interested in the design of the MATLAB language. She is an application engineer and writes here about MATLAB programming and related topics. Sun, 13 Oct 2019 07:32:14 +0000 hourly 1 https://wordpress.org/?v=6.2.2 Comment on Which Way to Compute: cellfun or for-loop? by Loren Shure https://blogs.mathworks.com/loren/2019/09/25/which-way-to-compute-cellfun-or-for-loop/#comment-48294 Sun, 13 Oct 2019 07:32:14 +0000 https://blogs.mathworks.com/loren/?p=3448#comment-48294 @Owen-

Thanks for your thoughts on this. Side effects can be a concern sometimes!

–loren

]]>
Comment on Which Way to Compute: cellfun or for-loop? by Owen Gray https://blogs.mathworks.com/loren/2019/09/25/which-way-to-compute-cellfun-or-for-loop/#comment-48292 Thu, 10 Oct 2019 19:33:05 +0000 https://blogs.mathworks.com/loren/?p=3448#comment-48292 What I would love to have is a parcellfun, I prefer cellfun to for-loops since it discourages side effects and the error handing syntax is very concise. Parallel version of all the *fun family would be great.

]]>
Comment on Which Way to Compute: cellfun or for-loop? by Loren Shure https://blogs.mathworks.com/loren/2019/09/25/which-way-to-compute-cellfun-or-for-loop/#comment-48286 Thu, 03 Oct 2019 14:49:46 +0000 https://blogs.mathworks.com/loren/?p=3448#comment-48286 @Sean and the others,

FWIW, I never use cellfun unless people are looking for a way they perceive to be simpler than the for-loop. It’s not worth me memorizing the special cases where cellfun is on par with the loop.

–Loren

]]>
Comment on Which Way to Compute: cellfun or for-loop? by Sean de Wolski https://blogs.mathworks.com/loren/2019/09/25/which-way-to-compute-cellfun-or-for-loop/#comment-48284 Thu, 03 Oct 2019 14:41:11 +0000 https://blogs.mathworks.com/loren/?p=3448#comment-48284 I always use for-loops which I find to be easier to understand, cleaner, and faster in any “program”. I’ll use cellfun() at the command line to get a list of empties or make some other index to quickly filter elements of a cell for interactive exploration. However, with string arrays, tables, and now arguments replacing varargin, I find myself using cells less and less.

]]>
Comment on Compose Yourself! by Loren Shure https://blogs.mathworks.com/loren/2019/09/09/compose-yourself/#comment-48282 Thu, 03 Oct 2019 12:27:08 +0000 https://blogs.mathworks.com/loren/?p=3438#comment-48282 @Yung-Yeh,

You are always on firmer ground if you use documented functions. Undocumented ones are often not fully designed or ready for use beyond a specific purpose that MathWorks team needs. As such, undocumented ones can change and disappear. Probably best if you do switch to compose.

–loren

]]>
Comment on Which Way to Compute: cellfun or for-loop? by Loren Shure https://blogs.mathworks.com/loren/2019/09/25/which-way-to-compute-cellfun-or-for-loop/#comment-48280 Thu, 03 Oct 2019 12:23:55 +0000 https://blogs.mathworks.com/loren/?p=3448#comment-48280 @Yung-Yeh,

Thanks for your thoughts.

]]>
Comment on Compose Yourself! by Yung-Yeh Chang https://blogs.mathworks.com/loren/2019/09/09/compose-yourself/#comment-48274 Sat, 28 Sep 2019 19:59:50 +0000 https://blogs.mathworks.com/loren/?p=3438#comment-48274 Very interesting…
Does anyone know this function sprintfc? It prints exactly the same result as compose does for most cases. It’s been introduced since…I don’t know…maybe around 2008.
If you type

help sprintfc
sprintfc is an undocumented builtin function.

I don’t know why Mathwokrs keeps sprintfc function undocumented and unsupported. But that’s a really helpful function.
Well…I think I would appripriate MATLAB for having compose as it’s a fully supported and documented function.

]]>
Comment on Which Way to Compute: cellfun or for-loop? by Yung-Yeh Chang https://blogs.mathworks.com/loren/2019/09/25/which-way-to-compute-cellfun-or-for-loop/#comment-48272 Sat, 28 Sep 2019 19:32:33 +0000 https://blogs.mathworks.com/loren/?p=3448#comment-48272 To me, it somehow depends on the purpose of a coding project. I usually value the readability the most. However, I sometimes value the purpose in higher priority. If I am writing an analysis code that needs to calculate many metrics, I prefer `cellfun` in this case. I don’t mind the overhead because this way, it’s easier to correct an error in the metrics table I am going to write out.
If I am writing a package or design a class, I use `for` to avoid possible overhead altogether.

]]>
Comment on Which Way to Compute: cellfun or for-loop? by Loren Shure https://blogs.mathworks.com/loren/2019/09/25/which-way-to-compute-cellfun-or-for-loop/#comment-48268 Fri, 27 Sep 2019 19:53:25 +0000 https://blogs.mathworks.com/loren/?p=3448#comment-48268 @Todd – Thanks for the input. Please put in an enhancement request with siupport about pagefun so it’s sure to get on the list of features to consider.

–loren

]]>
Comment on Which Way to Compute: cellfun or for-loop? by Todd Schultz https://blogs.mathworks.com/loren/2019/09/25/which-way-to-compute-cellfun-or-for-loop/#comment-48266 Fri, 27 Sep 2019 14:53:02 +0000 https://blogs.mathworks.com/loren/?p=3448#comment-48266 I would say that I tend to use cell fun, but I’ll have to start to check that choice. However, the one I really like is pagefun in the Parallel Computing Toolbox. I would love for that function to work in base MATLAB!

]]>