MX_SLFS – Save or load a Matrix/Vector into file or string

Block SymbolLicensing group: STANDARD
Qt SVG Document Exported by REXYGEN Studio uMV uStr LOAD SAVE yMV yStr iE MX_SLFS

Function Description
The block allows to convert a matrix or vector into text form and vice versa. The matrix is supplied as a reference to the uMV input. The yMV output refers to the same matrix as the uMV input, and is intended to chain matrix blocks in the correct order, as is common with all MATRIX blocks.

The text can be either in the input uStr (or output yStr for the opposite direction of conversion) or in the file. If the text is in a file, its name is the string connected to the uStr input. The usual REXYGEN system file name rules applies, ie it is relative to datadir and ../ is not allowed to leave the directory. If the uStr input is unattached (or empty string), the path name of the file is used with the full path (that is, including the task name and all subsystems) with the .dat extension.

The format of a matrix in a text file or in text input and output is determined by the format parameter. Supported English and Czech CSV (i.e., columns separated by comma or semicolon), JSON format (created by Google and often used in web applications) and the format used by MATLAB (for entering a matrix in MATLAB scripts).

Conversion from text to matrix/vector or vice versa can be performed at each step of the algorithm or is triggered by the LOAD and SAVE inputs. The exact method is determined by the mode parameter:

  • 1: level-triggered file: data are converted from a file to a matrix when LOAD = on and from a matrix to a file when SAVE = on; if both signals are active, it is an error and no action is taken,
  • 2: edge-triggered file: data are converted from a file to a matrix on the rising edge (off on) of the LOAD input and from a matrix to a file on the rising edge of the SAVE input; if there are rising edges on both signals, it is an error and no action is taken,
  • 3: level-triggered string: data are converted from the uStr input to a matrix when LOAD = on and from a matrix to the yStr output when SAVE = on; if both signals are active, it is an error and no action is taken,
  • 4: edge-triggered string: data are converted from the uStr input to a matrix on the rising edge of the LOAD input and from a matrix to the yStr output on the rising edge of the SAVE input; if there are rising edges on both signals, it is an error and no action is taken,
  • 5: continuous string to matrix: data are converted from the uStr input to a matrix at each step of the algorithm,
  • 6: continuous matrix to string: data are converted from a matrix to the yStr output at each step of the algorithm,
  • 7: continuous file to matrix: data are converted from a file to a matrix at each step of the algorithm,
  • 8: continuous matrix to file: data are converted from a matrix to a file at each step of the algorithm.

If an error occurs, it is signaled to the iE output and in the log. After a fatal error, the conversion from/to the matrix stops. Error reset for mode = 1 .. 4 is done by setting LOAD = SAVE = off, resetting fatal error cannot be performed for mode = 5 .. 8 (must switch to mode = 1 .. 4 and then back).

The nmax parameter is used to allocate the output string. If nmax> 0, it is allocated specified number of chars during initialization. If this amount is insufficient, the block reports an error. If nmax = 0, the block increases the length of the output string as needed. If user don’t specify the nmax parameter it can lead to full RAM memory in extreme situations and unpredictable behaviour of entire system.

This block does not propagate the signal quality. More information can be found in the 1.4 section.

Input

uMV

Input reference to a matrix or vector

Reference

uStr

Input string (to convert into matrix) or filename

String

LOAD

Trigger to move data to matrix/vector

Bool

SAVE

Trigger to move data from matrix/vector

Bool

Parameter

mode

Triggering mode  2

Long (I32)

1 ....

level-triggered file

2 ....

edge-triggered file

3 ....

level-triggered string

4 ....

edge-triggered string

5 ....

continuous string to matrix

6 ....

continuous matrix to string

7 ....

continuous file to matrix

8 ....

continuous matrix to file

format

String/file format  1

Long (I32)

1 ....

CSV

2 ....

CSV(semicolon)

3 ....

JSON

4 ....

MATLAB

prec

Number of digits for single value   0  20 6

Long (I32)

TRN

Transposition flag

Bool

nmax

Allocated size of string   0

Long (I32)

Output

yMV

Output reference to a matrix or vector

Reference

yStr

String representation of the matrix/vector

String

iE

Error code

Error

2024 © REX Controls s.r.o., www.rexygen.com