ReadVariablesFromFile
Versione 1.0.0 (8,23 KB) da
Miguel Couceiro
Read variables from ASCII file and returns a two column cell array with the variable name (first col) and the variable value (second col)
Description:
Read arbitrary variables from a text file
Input parameters:
fileName (mandatory) = Name of the text file (including aboslute or relative path) from which the variables should be read
The file must contain variables declared as Matlab attributions, like:
variableName = variableValue
where "variableName" is the name of the variable to be set and "variableValue" the corresponding value, which can be of any type (single value or array, including cell array). No semicolumns should be used to terminate the statement.
A single statement can be spread across several lines, by using the three dots (...) matlab notation. Empty paragraphs are discarded. Comments can be preceeded by % or # character, and will be discarded.
Output parameters:
This function returns an Nx2 text cell array of strings. Each of the N lines of the cell array contains the data corresponding to a given variable.
For a given line of the cell array:
the first column contains the name of the variable (in string format);
the second column contains the value of the variable (in string format).
The output can be used to set variables in any point of a given code, by using, e.x., the following code
for i = 1:size(importedVariables,1)
eval(strcat(importedVariables{i,1}, ' = ' , importedVariables{i,2}, ';'));
end
Example:
An ASCII file is provided and can be used to test the code.
Cita come
Miguel Couceiro (2024). ReadVariablesFromFile (https://www.mathworks.com/matlabcentral/fileexchange/96409-readvariablesfromfile), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Creato con
R2020b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS LinuxTag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
ReadVariablesFromFile
Versione | Pubblicato | Note della release | |
---|---|---|---|
1.0.0 |