Tutorial by Examples

This simple example provides an explanation on some functions I found extremely useful since I have started using MATLAB: cellfun, arrayfun. The idea is to take an array or cell class variable, loop through all its elements and apply a dedicated function on each element. An applied function can eith...
It is possible to change Code Folding preference to suit your need. Thus code folding can be set enable/unable for specific constructs (ex: if block, for loop, Sections ...). To change folding preferences, go to Preferences -> Code Folding: Then you can choose which part of the code can be f...
On a few occasions, I have had an interesting figure I saved but I lost an access to its data. This example shows a trick how to achieve extract information from a figure. The key functions are findobj and get. findobj returns a handler to an object given attributes or properties of the object, suc...
Anonymous functions can be used for functional programming. The main problem to solve is that there is no native way for anchoring a recursion, but this can still be implemented in a single line: if_ = @(bool, tf) tf{2-bool}(); This function accepts a boolean value and a cell array of two functi...
By putting multiple figure handles into a graphics array, multiple figures can be saved to the same .fig file h(1) = figure; scatter(rand(1,100),rand(1,100)); h(2) = figure; scatter(rand(1,100),rand(1,100)); h(3) = figure; scatter(rand(1,100),rand(1,100)); savefig(h,'ThreeRandomScatterp...
If you want to comment part of your code, then comment blocks may be useful. Comment block starts with a %{ in a new line and ends with %} in another new line: a = 10; b = 3; %{ c = a*b; d = a-b; %} This allows you fo fold the sections that you commented to make the code more clean and comp...

Page 1 of 1