For this example, first let's create some *. Let's start with a simple problem and say we need to find a list of *.mat files given the folder. An applied function can either be anonymous, which is usually a case, or any regular function define in a *.m file. The idea is to take an array or cell class variable, loop through all its elements and apply a dedicated function on each element. This simple example provides an explanation on some functions I found extremely useful since I have started using MATLAB: cellfun, arrayfun. # Useful functions that operate on cells and arrays Then the graphics array can be saved using savefig like with a normal figure, but with the handle to the graphics array as an additional argument.Īn interesting side note is that the figures will tend to stay arranged in the same way that they were saved when you open them. This creates 3 scatterplots of random data, each part of graphic array h. 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, 'ThreeRandomScatterplots.fig' ) close (h ) The following code creates an example figure that shows two lines a sin function and a threshold and a legend It turns out that the Line objects hold all data in following properties: XData, YData, and ZData the last one is usually 0 unless a figure contains a 3D plot. Once a line object has been found, get (opens new window) can return any value held by properties. findobj (opens new window) returns a handler to an object given attributes or properties of the object, such as Type or Color, etc. The key functions are findobj (opens new window) and get (opens new window). This example shows a trick how to achieve extract information from a figure. I'd like the yellow-highlighted color back. Now with 2021b, there is a blue bar on the left to indicate the current section. On a few occasions, I have had an interesting figure I saved but I lost an access to its data. Prior to the changeover (versions 2021a and older), the current section in the Editor would be highlighted a yellowish color. You will be able to fold sections to have a general overview of your Then instead of seeing a long source code similar to : Sections are delimitedĮxample: To enable it check the "Sections" box: Note that folding is persistent, in the sense that part of the code that has been expanded/collapsed will keep their status after Matlab or the m-file has been closed and is re-open.Īn interesting option is to enable to fold Sections. Note that you can also expand or collapse all of the code in a fileīy placing your cursor anywhere within the file, right-click, and then select Code Folding > Expand All or Code Folding > Fold All from the context menu.Then you can choose which part of the code can be folded. To change folding preferences, go to Preferences -> Code Folding: Thus code folding can be set enable/unable for specific constructs (ex: if block, for loop, Sections. It is possible to change Code Folding preference to suit your need. # Useful tricks # Code Folding Preferences Useful functions that operate on cells and arrays.Functional Programming using Anonymous Functions. ![]() Ordinary Differential Equations (ODE) Solvers.Fourier Transforms and Inverse Fourier Transforms.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |