Difference between revisions of "Matlab cell array"

From Dynamo
Jump to navigation Jump to search
Line 38: Line 38:
 
The names of the model files in a catalogue can be easily extracted with the command line <tt>dcm</tt> utility. In the command:
 
The names of the model files in a catalogue can be easily extracted with the command line <tt>dcm</tt> utility. In the command:
  
<tt>dcm myCatalogue -i * -l m -ws o </tt>
+
<tt>dcm myCatalogue -i * -l m -ws o </tt>
  
 
the flags have the meaning:
 
the flags have the meaning:
# <tt>-i * </tt>
+
* <tt>-i * </tt> : visit all (<tt>*</tt>) volume indices (<tt>-i<tt>)
# <tt>-i * </tt>
+
* <tt> -l m </tt>: on each visited volume (<tt>-l</tt>) list all the models (<tt>m<tt>)
# <tt>-ws o </tt>
+
* <tt>-ws o </tt>: put the results in a workspace variable (<tt>-ws</tt>) arbitrarily called <tt>o</tt>
  
 
so that the order will show  on screen the names of all the models inside the catalogue <tt>myCatalogue</tt>.
 
so that the order will show  on screen the names of all the models inside the catalogue <tt>myCatalogue</tt>.

Revision as of 12:41, 2 February 2017

The cell array is a Matlab container for the storage of series of objects in the memory workspace. Individuals elements are accessed or created with the curly bracket {} notation. Cell arrays are available both in Matlab and in the standalone versions of Dynamo.


Basic syntax

Some basic examples:

a = {};

creates an empty cell array called a in the memory workspace.

a = {'hello','bye'};

creates a cell array that contains the strings hello and bye, so that

disp(a{1}); will just write the string hello in the Matlab desktop ( or in the Dynamo standalone console).

Individual elements can be added through the {}notation:

a{3} = 'hi again';

will enlarge the cell array with a third element.


A complete (and rather lengthy) description can be found in the |matlab page

Cell arrays in Dynamo

Cell arrays are frequently of interest for Dynamo users that need to perform operations that are complicated or not available through the GUIs.

Loops on models

Extracting model files from a catalogue

The names of the model files in a catalogue can be easily extracted with the command line dcm utility. In the command:

dcm myCatalogue -i * -l m -ws o 

the flags have the meaning:

  • -i *  : visit all (*) volume indices (-i)
  • -l m : on each visited volume (-l) list all the models (m)
  • -ws o : put the results in a workspace variable (-ws) arbitrarily called o

so that the order will show on screen the names of all the models inside the catalogue myCatalogue.