Extracting table from data structure
古いコメントを表示
Hello,
I have multile .mat files and from these files I want to extract the table with variable name B (500000×1 double). At first, I have loaded data using S = dir('*.mat'); and then I am using commond K = S.B; to extract the data from table variable name B. This commond doesnot work and gave me this message: Reference to non-existent field 'B'.. Can you guide me which commond will I use to extract the table data from data structure.
Br,
Haresh Kumar
4 件のコメント
Stephen23
2021 年 4 月 6 日
"Reference to non-existent field 'B'."
Where S is your structure, show us the complete output of this command:
fieldnames(S)
Haresh Kumar
2021 年 4 月 6 日
Haresh Kumar
2021 年 4 月 6 日
回答 (2 件)
Hiro Yoshino
2021 年 4 月 6 日
First thing you should do is check if S is a table variable.
If it turns out to be a table variable, then the next thing would be running the following command to check if B exists
S.Properties.VariableNames
Good luck.
3 件のコメント
Haresh Kumar
2021 年 4 月 6 日
Hiro Yoshino
2021 年 4 月 6 日
type S in the command window to see what fields S has.
Haresh Kumar
2021 年 4 月 6 日
At first, I have loaded data using S = dir('*.mat');
The dir function does not load data. All it does is generate a list of files in the directory with the .mat extension. To load the data you'll need to use the load function. Then if you want to check if the loaded data contains a variable named B (that has been loaded into a field of the output of load you can use isfield.
data = load('census.mat')
doesItHaveAVariableB = isfield(data, 'B')
doesItHaveAVariableCdate = isfield(data, 'cdate')
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!