Renaming loaded variable with initially unknown name

13 次查看(过去 30 天)
Hello All,
Currently I am working with genome scale models. So, I have .mat files of those models. After loading the files, I get random variables (suppose: xyz, data type: 1x1 struct) in my workspace. I want to fetch variables inside the loaded variable. Like xyz.reactions or xyz.genes. But I am unable to get the name 'xyz'. How can I rename them automaically without knowing the variable names?
I tried > model = load('filename.mat'); but this creates a struct with the unknown name inside model, so unable to fetch variables in it.
Any suggestions would be highly appreciated!
Thanks!

采纳的回答

Steven Lord
Steven Lord 2021-3-30
data = load('census.mat')
data = struct with fields:
cdate: [21×1 double] pop: [21×1 double]
variableNames = fieldnames(data)
variableNames = 2×1 cell array
{'cdate'} {'pop' }
dataFromVariable1 = data.(variableNames{1})
dataFromVariable1 = 21×1
1790 1800 1810 1820 1830 1840 1850 1860 1870 1880
fprintf('Variable %s from census.mat is %s\n', variableNames{1}, mat2str(dataFromVariable1))
Variable cdate from census.mat is [1790;1800;1810;1820;1830;1840;1850;1860;1870;1880;1890;1900;1910;1920;1930;1940;1950;1960;1970;1980;1990]

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genomics and Next Generation Sequencing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by