Extracting table from data structure

3次观看(最近30天)
Haresh Kumar
Haresh Kumar 2021年4月6日
Commented: Haresh Kumar2021年4月6日
Hello,
我有多级.mat文件,从这些文件中我想提取具有可变名称B(500000×1 double)的表。首先,我使用s = dir('*。mat')加载了数据;然后我使用conson k = s.b;要从表变量名称B提取数据B。这个commond不起作用,而是给我这个消息:引用不存在的字段'b'..您能指导我哪个commond我将使用哪个commond从数据结构中提取表数据。
br
Haresh Kumar
4条评论
Haresh Kumar
Haresh Kumar 2021年4月6日
Hello,
Let me make it simple. I am giving directory path inorder to run the multiple .mat files from the folder. Each .mat file (number (1)......number(n)) contains multiple tables from which I only want the table of variable B. Now, you can guide which commond will I use to get the data from variable B (Table)
br
Haresh Kumar

Sign in to comment.

答案(2)

Hiro
Hiro 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 Comments
Haresh Kumar
Haresh Kumar 2021年4月6日
name
folder
date
字节
isdir
datenum

Sign in to comment.


Steven Lord
Steven Lord 2021年4月6日
首先,我使用s = dir('*。mat')加载了数据;
The dir 功能 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 功能。然后,如果要检查加载数据是否包含一个名为b的变量(已加载到输出的字段中 load you can use isfield .
data = load('census.mat')
data =struct with fields:
cdate: [21×1 double] pop: [21×1 double]
doesItHaveAVariableB = isfield(data,'B')
doesItHaveAVariableB =logical
0
doesItHaveAVariableCdate = isfield(数据,'cdate')
doesItHaveAVariableCdate =logical
1

Community Treasure Hunt

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

开始狩猎!