ReadVariablesFromFi​le

バージョン 1.0.0 (8.23 KB) 作成者: 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)
ダウンロード: 12
更新 2021/7/24

ライセンスの表示

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.

引用

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

MATLAB リリースの互換性
作成: R2020b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
タグ タグを追加

Community Treasure Hunt

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

Start Hunting!

ReadVariablesFromFile

バージョン 公開済み リリース ノート
1.0.0