Start of trail End of trail navigation bar

Table of Contents

qc_get_expression_parts

Creates a cell array of vector or matrix element strings from a single input string input representing a vector or matrix.

Syntax

      text = qc_get_expression_parts(expression) % Convert expression string into cell array of individual
                                                 % vector or matrix elements as strings.
    

Description

If you are creating an interface that requires the user to input a vector or matrix for further evaluation within your script, but you do not want to simply evaluate the entire vector or matrix in order to preserve variables that are entered, then this function can aid in the extraction of the various elements for further processing.

The input string should be in standard MATLAB scalar, vector, or matrix notation. The variables do not need to be defined except for terms where a range operator is included. If a range operator is found, the corresponding elements will be evaluated, and the resulting numbers will be returned as strings in the corresponding vector or matrix locations in the cell array.

Parameters

expression

A string in the form of a scalar, vector (n x 1 or 1 x n), or matrix (m x n). The use of square brackets is optional. They will be ignored.

Outputs

text

A cell array of strings in the same size of the original scalar (1 x 1), vector (n x 1 or 1 x n), or matrix (m x n) expression

Examples

      text = qc_get_expression_parts('[a b (1 + 3)]'); % This will return:
                                                       %
                                                       % 'a'    'b'    '(1 + 3)'

      text = qc_get_expression_parts('[a b c; 1:3]');  % This will return:
                                                       %
                                                       % 'a'    'b'    'c'
                                                       % '1'    '2'    '3'
                                                       %
                                                       % Note that in this case the range operator needed to be evaluated,
                                                       % but the values were returned as strings.
      
      text = qc_get_expression_parts('[a]');           % This will return:
                                                       %
                                                       % 'a' 
                                                       %
                                                       % This allows your scipt to handle vectors, matricies and scalars.
      
            
    

 

navigation bar