ReadVariablesFromFi​le

Read variables from ASCII file and returns a two column cell array with the variable name (first col) and the variable value (second col)
12 Downloads
Aktualisiert 24 Jul 2021

Lizenz anzeigen

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.

Zitieren als

Miguel Couceiro (2024). ReadVariablesFromFile (https://www.mathworks.com/matlabcentral/fileexchange/96409-readvariablesfromfile), MATLAB Central File Exchange. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2020b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Tags Tags hinzufügen

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

ReadVariablesFromFile

Version Veröffentlicht Versionshinweise
1.0.0